Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Kotlin - Padrões e Boas Práticas
Search
Rafael Toledo
November 18, 2017
Programming
740
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin - Padrões e Boas Práticas
Apresentada no DevFest Belo Horizonte 2017
Rafael Toledo
November 18, 2017
Transcript
59 slides
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
More Decks by Rafael Toledo
See All by Rafael Toledo
Gamedev com Kotlin Native
rafaeltoledo
0
130
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
330
Motion Layout
rafaeltoledo
1
200
Pipeline Android
rafaeltoledo
3
220
Android Architecture Components
rafaeltoledo
7
240
What's New in Kotlin 1.3
rafaeltoledo
0
190
An Overview of Multiplatform Kotlin
rafaeltoledo
2
190
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
320
Android Assíncrono
rafaeltoledo
3
260
Other Decks in Programming
See All in Programming
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
420
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
810
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
450
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
180
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
210
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
あなたはMCPの機能を、まだ知らない。
4geru
1
740
AppFunctionsの内部実装を紐解く
hiroaki404
0
120
はじめてのPLATEAU
nokonoko1203
1
670
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.6k
Skills Are the New npm [AAIF Bengaluru, Nov 2026]
shivamsaraswat
0
120
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Documentation Writing (for coders)
carmenintech
77
5.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7.1k
Evolving SEO for Evolving Search Engines
ryanjones
0
370
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
570
How to Talk to Developers About Accessibility
jct
2
630
The agentic SEO stack - context over prompts
schlessera
0
1k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k