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
720
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
79
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
290
Motion Layout
rafaeltoledo
1
130
Pipeline Android
rafaeltoledo
3
150
Android Architecture Components
rafaeltoledo
7
160
What's New in Kotlin 1.3
rafaeltoledo
0
150
An Overview of Multiplatform Kotlin
rafaeltoledo
2
120
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
260
Android Assíncrono
rafaeltoledo
3
220
Other Decks in Programming
See All in Programming
オープンセミナー2025@広島「君はどこで動かすか?」アンケート結果
satoshi256kbyte
0
230
時間軸から考えるTerraformを使う理由と留意点
fufuhu
7
1.9k
CSC305 Summer Lecture 12
javiergs
PRO
0
130
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
130
パスタの技術
yusukebe
1
550
The state patternの実践 個人開発で培ったpractice集
miyanokomiya
0
160
Vue・React マルチプロダクト開発を支える Vite
andpad
0
110
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
11
3.1k
AIでLINEスタンプを作ってみた
eycjur
1
220
兎に角、コードレビュー
mitohato14
0
160
物語を動かす行動"量" #エンジニアニメ
konifar
14
5.7k
rage against annotate_predecessor
junk0612
0
150
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
110
20k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Raft: Consensus for Rubyists
vanstee
140
7.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Scaling GitHub
holman
463
140k
Being A Developer After 40
akosma
90
590k
Building Adaptive Systems
keathley
43
2.7k
Testing 201, or: Great Expectations
jmmastey
45
7.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
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