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
730
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
More Decks by Rafael Toledo
See All by Rafael Toledo
Gamedev com Kotlin Native
rafaeltoledo
0
120
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
320
Motion Layout
rafaeltoledo
1
190
Pipeline Android
rafaeltoledo
3
210
Android Architecture Components
rafaeltoledo
7
230
What's New in Kotlin 1.3
rafaeltoledo
0
180
An Overview of Multiplatform Kotlin
rafaeltoledo
2
180
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
300
Android Assíncrono
rafaeltoledo
3
250
Other Decks in Programming
See All in Programming
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
190
Java 27新機能 / Java 27 new features
kishida
2
140
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
130
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.2k
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
330
AHC070解法紹介
eijirou
0
120
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
390
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
170
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.4k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
0
280
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
170
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
We Are The Robots
honzajavorek
0
370
Designing for Performance
lara
611
70k
The Pragmatic Product Professional
lauravandoore
37
7.4k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
The browser strikes back
jonoalderson
0
1.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Un-Boring Meetings
codingconduct
0
420
The SEO Collaboration Effect
kristinabergwall1
1
560
Music & Morning Musume
bryan
48
7.4k
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