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
Klean Code with Kotlin
Search
oshai
November 26, 2019
Technology
77
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Klean Code with Kotlin
oshai
November 26, 2019
More Decks by oshai
See All by oshai
Maintaining an Open Source The Good, Bad & Ugly
oshai
0
37
KScript
oshai
0
21
JVM languages shootout - Java, Scala & *Kotlin*
oshai
0
64
Koroutinify ; Lessons learned from applying Coroutines in Kotlin Backend ; Deep dive into Coroutines
oshai
1
130
Klean that Code, Boil those Boilerplates
oshai
2
97
Scala vs. Kotlin; Friend or Foe?
oshai
0
170
No forks, One star. Now what?! — How I published my Kotlin Open-Source lib
oshai
0
87
Scala--pack your Future[T]; Kotlin is coming! (Kotlin TLV)
oshai
0
210
X tips [X==9] for building a Bulletproof Deployment Pipeline with Jenkins
oshai
0
62
Other Decks in Technology
See All in Technology
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
130
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
280
Kiro Meetup #8 Kiro アップデート (2026/3/21〜2026/9/24)
katzueno
1
160
AIエージェントの権限管理 3: Agentic RAG の Fine grained access control 編
ren8k
0
240
登壇の自信を奪う3匹のオバケ / 3 Ghosts That Rob You of Your Confidence in Public Speaking
pauli
9
1.1k
30座EKS, 180次升級淬煉的EKS Upgrade Skill 的歷程
eric8230
0
210
SREへの勘違いに気づいた後の話
tomodakengo
0
150
Railsのように考える: See through the Master
snoozer05
PRO
5
1.3k
データ界隈LT祭 第1回LT登壇
taromatsui_cccmkhd
2
1.5k
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.4k
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
33
31k
負債のメタファと2026年 / Debt Metaphor in Agentic Engineering Age 202609 Edition
twada
PRO
11
6.5k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.8k
Code Reviewing Like a Champion
maltzj
528
40k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
BBQ
matthewcrist
89
10k
The SEO Collaboration Effect
kristinabergwall1
1
570
A Soul's Torment
seathinner
8
3.6k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
Test your architecture with Archunit
thirion
2
2.4k
Transcript
Klean Code with Kotlin
IS THERE A DOCTOR IN THE AUDIENCE?
IS THERE A DOCTOR JAVA DEVELOPER IN THE AUDIENCE?
Should I start using Kotlin?
TL;DL* - YES! *Too Long; Didn’t Listen
• Look at trends • Compare Kotlin to Java •
More Kotlin features Plan B
Google Trends - Kotlin
None
None
None
None
None
Why do developers ❤ Kotlin?
None
Boilerplate In computer programming, boilerplate code or boilerplate refers to
sections of code that have to be included in many places with little or no alteration. It is often used when referring to languages that are considered verbose, i.e. the programmer must write a lot of code to do minimal jobs.
Boilerplate boilerplate - little or no alteration. verbose a lot
of code to do minimal jobs.
Java is Verbose
IDE
Hello Kotlin! Java public class Hello { public static void
main(String[] args) { System.out.println("Hello!"); } } Kotlin fun main() { println("Hello!") }
POJO Class Java public class AdCpcData { private int adId;
private double cpc; }
POJO Class Java public class AdCpcData { private int adId;
private double cpc; public AdCpcData(final int adId, final double cpc) { this.adId = adId; this.cpc = cpc; } public double getCpc() { return cpc; } public int getAdId() { return adId; } public void setAdId(final int adId) { this.adId = adId; } public void setCpc(final double cpc) { this.cpc = cpc; } }
POJO Class Java public class AdCpcData { private int adId;
private double cpc; public AdCpcData(final int adId, final double cpc) { this.adId = adId; this.cpc = cpc; } public double getCpc() { return cpc; } public int getAdId() { return adId; } public void setAdId(final int adId) { this.adId = adId; } public void setCpc(final double cpc) { this.cpc = cpc; } } equals(), hashcode(), toString()…
POJO Class Java public class AdCpcData { private int adId;
private double cpc; public AdCpcData(final int adId, final double cpc) { this.adId = adId; this.cpc = cpc; } public double getCpc() { return cpc; } public int getAdId() { return adId; } public void setAdId(final int adId) { this.adId = adId; } public void setCpc(final double cpc) { this.cpc = cpc; } @Override public String toString() { return com.google.common.base.Objects.toStringHelper(this) .add("adId", adId) .add("cpc", cpc) .toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AdCpcData adCpcData = (AdCpcData) o; return adId == adCpcData.adId && Double.compare(adCpcData.cpc, cpc) == 0; } @Override public int hashCode() { return Objects.hash(adId, cpc); } } equals(), hashcode(), toString()…
POJO Class Java public class AdCpcData { private int adId;
private double cpc; public AdCpcData(final int adId, final double cpc) { this.adId = adId; this.cpc = cpc; } public double getCpc() { return cpc; } public int getAdId() { return adId; } public void setAdId(final int adId) { this.adId = adId; } public void setCpc(final double cpc) { this.cpc = cpc; } @Override public String toString() { return com.google.common.base.Objects.toStringHelper(this) .add("adId", adId) .add("cpc", cpc) .toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AdCpcData adCpcData = (AdCpcData) o; return adId == adCpcData.adId && Double.compare(adCpcData.cpc, cpc) == 0; } @Override public int hashCode() { return Objects.hash(adId, cpc); } } equals(), hashcode(), toString()… 57 LOC
Data Class Java public class AdCpcData { private int adId;
private double cpc; public AdCpcData(final int adId, final double cpc) { this.adId = adId; this.cpc = cpc; } public double getCpc() { return cpc; } public int getAdId() { return adId; } public void setAdId(final int adId) { this.adId = adId; } public void setCpc(final double cpc) { this.cpc = cpc; } @Override public String toString() { return com.google.common.base.Objects.toStringHelper(this) .add("adId", adId) .add("cpc", cpc) .toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; AdCpcData adCpcData = (AdCpcData) o; return adId == adCpcData.adId && Double.compare(adCpcData.cpc, cpc) == 0; } @Override public int hashCode() { return Objects.hash(adId, cpc); } } Kotlin data class AdCpcData( var adId: Int, var cpc: Double )
Variable declaration Java private final Map<String, String> myMap = new
HashMap<>(); myMap.put("Hi", "There"); Kotlin val myMap = mapOf("Hi" to "There")
Testing Java @Test public void testShouldProcessCampaign_WhenFlyToInRange() throws Exception { …
} Kotlin @Test fun `when "fly to" is in range - should process the campaign`() { TODO() }
Java vs Kotlin • Many more boilerplate examples… • But
Java do make some progress…
None
• We saw some statistics • We learned about boilerplate
Recap
Some more cool features
Extension method fun Int.hours() = TimeUnit.HOURS.toMillis(this.toLong()) … 5.hours()
Collections val fruits = listOf("banana", "avocado", "apple", "kiwi") fruits .filter
{ it.startsWith("a") } .sortedBy { it } .map { it.toUpperCase() } .forEach { println(it) }
When Expression when (object) { 1 -> "One" "Hello" ->
"Greeting" is Long -> "Long" in 2..10 -> "obj is in the range" else -> "Unknown" }
Inter-Op with Java Java adCpcData.getAdId() Kotlin adCpcData.adId
Null Safety val world: String? = null println(world.toUpperCase()) // In
Java you will get NPE // In Kotlin you will get compilation error
Null Safety val world: String? = null if (world !=
null) { println(world.toUpperCase()) } // In Java you will get NPE // In Kotlin you will get compilation error
Many More Features • String Interpolation • Named Parameters •
Smart Casting • Contracts • Multiline Strings
Why Kotlin? • Concise • Safe • Interoperable • Tool-friendly
• Practical
None
⌘ + ⌥ + ⇧ + K
Questions?
Thank You! @OhadShai