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
680
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
48
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
270
Motion Layout
rafaeltoledo
1
100
Pipeline Android
rafaeltoledo
3
130
Android Architecture Components
rafaeltoledo
7
130
What's New in Kotlin 1.3
rafaeltoledo
0
110
An Overview of Multiplatform Kotlin
rafaeltoledo
2
110
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
200
Android Assíncrono
rafaeltoledo
3
190
Other Decks in Programming
See All in Programming
"config" ってなんだ? / What is "config"?
okashoi
0
240
雑に思考を整理する技術と効能
konifar
58
29k
Hanami and htmx
bkuhlmann
0
210
Apache Hive 4 on Treasure Data
ryukobayashi
0
120
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
410
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
0
830
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
PHPはいつから死んでいるかの調査
chiroruxx
1
400
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
300
Git Rebase
bkuhlmann
11
1.6k
今、知っておきたい! 生成AIエージェントの世界
elith
3
350
Featured
See All Featured
Side Projects
sachag
451
41k
How STYLIGHT went responsive
nonsquared
92
4.8k
The Invisible Customer
myddelton
114
12k
Docker and Python
trallard
34
2.7k
Designing for humans not robots
tammielis
248
25k
A Modern Web Designer's Workflow
chriscoyier
689
190k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
60
14k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.6k
Building Adaptive Systems
keathley
31
1.9k
YesSQL, Process and Tooling at Scale
rocio
164
13k
Building an army of robots
kneath
300
41k
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