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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Rafael Toledo
November 18, 2017
Programming
1
730
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
110
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
300
Motion Layout
rafaeltoledo
1
160
Pipeline Android
rafaeltoledo
3
180
Android Architecture Components
rafaeltoledo
7
180
What's New in Kotlin 1.3
rafaeltoledo
0
160
An Overview of Multiplatform Kotlin
rafaeltoledo
2
150
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
280
Android Assíncrono
rafaeltoledo
3
240
Other Decks in Programming
See All in Programming
How to stabilize UI tests using XCTest
akkeylab
0
130
AHC061解説
shun_pi
0
380
Codex の「自走力」を高める
yorifuji
0
1.2k
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.4k
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.8k
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
モダンOBSプラグイン開発
umireon
0
130
CDIの誤解しがちな仕様とその対処TIPS
futokiyo
0
220
Claude Code Skill入門
mayahoney
0
390
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
110
[SF Ruby Feb'26] The Silicon Heel
palkan
0
110
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
550
Featured
See All Featured
Crafting Experiences
bethany
1
87
Believing is Seeing
oripsolob
1
84
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
[SF Ruby Conf 2025] Rails X
palkan
2
830
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
200
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
63
51k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
150
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
550
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
140
From π to Pie charts
rasagy
0
150
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
190
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