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
Rubyと自由とAIと
yotii23
6
1.4k
SwiftUI Viewの責務分離
elmetal
PRO
2
260
Rubyで始める関数型ドメインモデリング
shogo_tksk
0
140
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
150
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
940
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
160
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
150
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
290
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.6k
コードを読んで理解するko build
bells17
1
110
AIプログラミング雑キャッチアップ
yuheinakasaka
17
4k
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
190
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
Mobile First: as difficult as doing things right
swwweet
223
9.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
10
510
For a Future-Friendly Web
brad_frost
176
9.6k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Gamification - CAS2011
davidbonilla
80
5.2k
Bash Introduction
62gerente
611
210k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
We Have a Design System, Now What?
morganepeng
51
7.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
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