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
コードを読んで理解するko build
bells17
1
110
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
CDK開発におけるコーディング規約の運用
yamanashi_ren01
2
250
CI改善もDatadogとともに
taumu
0
200
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
データベースのオペレーターであるCloudNativePGがStatefulSetを使わない理由に迫る
nnaka2992
0
230
5分で理解する SOLID 原則 #phpcon_nagoya
shogogg
1
300
たのしいSocketのしくみ / Socket Under a Microscope
coe401_
8
1.3k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
150
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
920
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
150
ソフトウェアエンジニアの成長
masuda220
PRO
12
2.1k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Being A Developer After 40
akosma
89
590k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Building an army of robots
kneath
303
45k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Fireside Chat
paigeccino
34
3.2k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
133
33k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Writing Fast Ruby
sferik
628
61k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
640
A Tale of Four Properties
chriscoyier
158
23k
Transcript
None
None
None
None
None
None
None
None
None
User user = new User(); user.setName("Rafael Toledo"); // Obrigatório user.setEmail("rafaeltoledo@email.com");
// Obrigatório user.setPhone("+55 11 99999-9999"); // Opcional
User user = new User.Builder("Rafael Toledo", "rafaeltoledo@email.com") .phone("+55 11 99999-9999")
.build();
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "rafaeltoledo@email.com")
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "rafaeltoledo@email.com", 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