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
56
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
280
Motion Layout
rafaeltoledo
1
110
Pipeline Android
rafaeltoledo
3
130
Android Architecture Components
rafaeltoledo
7
130
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
220
Android Assíncrono
rafaeltoledo
3
200
Other Decks in Programming
See All in Programming
GenU導入でCDKに初挑戦し、悪戦苦闘した話
hideg
0
150
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
230
実践 Advanced CallKit 〜快適な通話の実現に向けて〜
mot_techtalk
3
120
『ドメイン駆動設計をはじめよう』中核の業務領域
masuda220
PRO
5
970
New Order in Cascade Sorting Order
mugi_uno
3
2.6k
REXML改善のその後
naitoh
0
190
Ruby Parser progress report 2024
yui_knk
2
220
A New Era of Testing
mannodermaus
2
230
私のEbitengineの第一歩
qt_luigi
0
440
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
260
エラーレスポンス設計から考える、0→1開発におけるGraphQLへの向き合い方
bicstone
5
1.5k
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
220
Featured
See All Featured
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
Making Projects Easy
brettharned
113
5.8k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.2k
Fireside Chat
paigeccino
31
2.9k
Designing the Hi-DPI Web
ddemaree
278
34k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
Documentation Writing (for coders)
carmenintech
65
4.3k
Infographics Made Easy
chrislema
239
18k
Build The Right Thing And Hit Your Dates
maggiecrowley
30
2.3k
Building Your Own Lightsaber
phodgson
101
6k
Facilitating Awesome Meetings
lara
49
5.9k
What the flash - Photography Introduction
edds
67
11k
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