Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin - Padrões e Boas Práticas
Search
Rafael Toledo
November 18, 2017
Programming
1
710
Kotlin - Padrões e Boas Práticas
Apresentada no DevFest Belo Horizonte 2017
Rafael Toledo
November 18, 2017
Tweet
Share
More Decks by Rafael Toledo
See All by Rafael Toledo
Gamedev com Kotlin Native
rafaeltoledo
0
59
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
290
Motion Layout
rafaeltoledo
1
120
Pipeline Android
rafaeltoledo
3
140
Android Architecture Components
rafaeltoledo
7
140
What's New in Kotlin 1.3
rafaeltoledo
0
130
An Overview of Multiplatform Kotlin
rafaeltoledo
2
110
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
240
Android Assíncrono
rafaeltoledo
3
200
Other Decks in Programming
See All in Programming
メンテが命: PHPフレームワークのコンテナ化とアップグレード戦略
shunta27
0
120
技術を根付かせる / How to make technology take root
kubode
1
250
color-scheme: light dark; を完全に理解する
uhyo
5
390
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
4
590
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.4k
GoとPHPのインターフェイスの違い
shimabox
2
190
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
520
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
390
SwiftUI Viewの責務分離
elmetal
PRO
1
240
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
160
PHPのバージョンアップ時にも役立ったAST
matsuo_atsushi
0
110
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
560
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
306
110k
Bash Introduction
62gerente
611
210k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Automating Front-end Workflow
addyosmani
1368
200k
Into the Great Unknown - MozCon
thekraken
35
1.6k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
How STYLIGHT went responsive
nonsquared
98
5.4k
Adopting Sorbet at Scale
ufuk
74
9.2k
Code Review Best Practice
trishagee
67
18k
Speed Design
sergeychernyshev
27
790
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Transcript
None
None
None
None
None
None
None
None
None
User user = new User(); user.setName("Rafael Toledo"); // Obrigatório user.setEmail("
[email protected]
");
// Obrigatório user.setPhone("+55 11 99999-9999"); // Opcional
User user = new User.Builder("Rafael Toledo", "
[email protected]
") .phone("+55 11 99999-9999")
.build();
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "
[email protected]
")
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "
[email protected]
", phone = "+55 11 99999-9999")
taxCalculator { country = Tax.COUNTRY_BRAZIL period { from = date("2017-01-01")
to = date("2017-10-31") } type = Tax.TYPE_IRPF payment { type = Tax.PAYMENT_BANK_TRANSFER bank { agency = "1234" account = "012345-9" ...
None
fun ViewGroup.inflate(layoutRes: Int, attachToRoot: Boolean = false): View { return
LayoutInflater.from(context).inflate(layoutRes, this, attachToRoot) }
None
None
None
None
None
validateAddress(addressFrom(jsonNode)) validateAddress(jsonNode.toAddress()) private fun JsonNode.toAddress() = Address( getRequired("street").asText(), getRequired("town").asText(), get("postcode")?.asPostCode(),
getRequired("country").asCountryCode())
validateAddress(addressFrom(jsonNode)) validateAddress(jsonNode.toAddress()) private fun JsonNode.toAddress() = Address( getRequired("street").asText(), getRequired("town").asText(), get("postcode")?.asPostCode(),
getRequired("country").asCountryCode())
// Antes enableCheckbox(isFreeDelivery(addressFrom(jsonNode))) // Depois enableCheckbox(jsonNode.toAddress().isFreeDelivery())
// Antes if (userCanEditSubmission(currentUser, submission)) { ... } // After
if (currentUser.canEdit(submission)) { ... }
None
None
None
None
None
None
None
None
None
None
if (savedInstanceState != null) { ... } savedInstanceState?.let { ...
}
None
None
// Confuso if (value?.isTrue ?: false) { ... } //
Parece redundante, mas é mais claro! if (value?.isTrue == true) { ... }
None
None
None
None
None
None
None
None
None
None
None
None
None
None
@Deprecated("Use X instead") @Throws(ExceptionInInitializerError::class) fun relevantMethod() { ... }
None
// Em vez de apply plugin: "kotlin-android" apply plugin: "kotlin-android-extensions"
// Por que não... apply plugin: "org.jetbrains.kotlin.android" apply plugin: "org.jetbrains.kotlin.android.extensions" apply plugin: "org.jetbrains.kotlin.kapt"
None
None
None