SlideShare a Scribd company logo
Haim Yadid / Next Insurance
mapOf(
taking?. kotlin to production
)
Seriously!!
Disclaimer
‫בה‬ ‫לנאמר‬ ‫לייחס‬ ‫ואין‬ ‫סאטירה‬ ‫תוכנית‬ ‫הינה‬ ‫זו‬ ‫תוכנית‬
‫כלשהי‬ ‫תכנות‬ ‫בשפת‬ ‫לפגוע‬ ‫ניסיון‬ ‫או‬ ‫אחרת‬ ‫משמעות‬ ‫שום‬
‫בה‬ ‫המופיעים‬ ‫מהתכנים‬ ‫נפגע‬ ‫חש‬ ‫הנך‬ ‫זאת‬ ‫בכל‬ ‫אם‬
‫מראש‬ ‫מתנצלים‬ ‫אנו‬ ‫בסקאלה‬ ‫מתכנת‬ ‫אתה‬ ‫אם‬ ‫או‬
About Me
❖ Developing software since 1984 (Boy, am I getting old?)
❖ Basic -> Pascal -> C -> C++ -> Java -> Kotlin
❖ Architect in Mercury
❖ Independent performance expert for 7 years
❖ Backend developer in
❖ Founded in the Beginning of 2016
❖ HQ@Palo Alto RnD@Kfar Saba
❖ Aims to disrupt the Small businesses insurance field
❖ Providing online experience which is simple fast and
transparent
❖ We started to write real code on May 2016
Kotlin
Java
Javascript
Node.JS
Dropwizard
RDS (mysql)
What is Kotlin ?
❖ Statically typed programming language
❖ for the JVM, Android and the browser (JS)
❖ 100% interoperable with Java™ (well almost)
❖ Developed by Jetbrains
❖ Revealed as an open source in July 2011
❖ v1.0 Release on Feb 2016
❖ 1.0.5 current stable version (28.11.2016)
Kotlin Features
❖ Concise
❖ Safe
❖ Versatile
❖ Practical
❖ Interoperable
Why Kotlin
Java Scala Cloju
Groovy/
JRuby
Java8
Strongly

Typed
Loosely

Typed
OO/verbose Functional/Rich
)))))))))))))))))))))))))))))))
Why Kotlin
Java Scala Cloju
Groovy/
JRuby
Java8
Strongly

Typed
Loosely

Typed
OO/verbose Functional/Rich
Kotlin )))))))))))))))))))))))))))))))
Scala can do it !! ?
❖ Yes Scala can do it
❖ Academic / Complicated
❖ Scala compile time is horrific
❖ Operator overloading -> OMG
Getting Started
❖ Kotlin has very lightweight standard library
❖ Mostly rely on Java collections for good (interop) and for
bad (all the rest)
❖ Kotlin compiles to Java6 byte code
❖ Has no special build tool just use Maven / Gradle
Kotlin & Android
❖ Kotlin got widely accepted on the android community
❖ Runtime has low footprint
❖ Compiles to …. Java 6
❖ Brings lambdas to Android dev and a lot of cool features
Trivial Stuff
❖ No new keyword
❖ No checked exceptions
❖ == structural equality
❖ === referencial equality
❖ No primitives (only under the hood)
❖ No arrays they are classes
❖ Any ~ java.lang.Object
Fun
❖ Functions are denoted with the fun keyword
❖ They can be member of a class
❖ Or top level functions inside a kotlin file
❖ can support tail recursion
❖ can be inlined
❖ fun funny(funnier: String) = "Hello world"
Fun Parameters
❖ Pascal notation
❖ Function parameters may have default values
❖ Call to function can be done using parameter names
fun mergeUser(first: String = "a", last: String) = first + last



fun foo() {

mergeUser(first="Albert",last= "Einstein")

mergeUser(last= "Einstein")

}
Extension functions
❖ Not like ruby monkey patching
❖ Only extend functionality cannot override
❖ Not part of the class
❖ Static methods with the receiver as first a parameter
fun String.double(sep: String) = "$this$sep$this"
❖ variables are declared using the keywords
❖ val (immutable)
❖ var (mutable)
❖
fun funny(funnier: String): String {

val x = "Hello world"

return x

}
val /var
Classes
❖ less verbose than Java
❖ no static members (use companion object)
❖ public is default
❖ Must be declared open to be overridden
❖ override keyword is mandatory
class Producer(val name:String, val value: Int)
Properties
❖ All members of classes are access via proper accessors
(getter and setters)
❖ The usage of getters and setters is implicit
❖ one can override implementation of setters and getters
Delegate Class
interface Foo {

fun funfun()

}



class FooImpl(val x: Int) : Foo {

override fun funfun() = print(x)

}



class Wrapper(f: Foo) : Foo by f



fun main(args: Array<String>) {

val f = FooImpl(10)

val wf = Wrapper(f)

wf.funfun() // prints 10

}
Smart Casts
❖ If you check that a class is of a certain type no need to
cast it
open class A {

fun smile() { println(":)")}

}



class B : A() {

fun laugh() = println("ha ha ha")

}



fun funnier(a: A) {

if (a is B ) {

a.laugh()

}

}
Null Safety
❖ Nullability part of the type of an object
❖ Option[T] Optional<T>
❖ Swift anyone ?
var msg : String = "Welcome"

msg = null
val nullableMsg : String? = null
Safe operator ?.
❖ The safe accessor operator ?. will result null
❖ Elvis operator for default
fun funny(funnier: String?): Int? {



println(x?.length ?: "")

return x?.length

}
Bang Bang !!
❖ The bang bang !! throws an NPE if object is null
fun funny(funnier: String?): String {

return funnier!!

}
Data classes
❖ Less powerful version of to case classes in Scala
❖ Implementation of
❖ hashcode() equals()
❖ copy()
❖ de structuring (component1 component2 …)
data class User(val firstName: String, val lastName:
String)



fun smile(user: User) {

val (first,last) = user

}
When
❖ Reminds Scala’s pattern matching but not as strong
❖ More capable than select in java
when (x) {

is Int -> print(x + 1)

is String -> print(x.length + 1)

is IntArray -> print(x.sum())

}
Sane Operator Overloading
❖ override only a set of the predefined operators
❖ By implementing the method with the correct name
Expression Translated to
a + b a.plus(b)
a - b a.minus(b)
a * b a.times(b)
a / b a.div(b)
a % b a.mod(b)
a..b a.rangeTo(b)
Sane Operator Overloading
data class Complex(val x: Double, val y: Double) {

operator fun inc(): Complex {

return Complex(x + 1, y + 1)

}



infix operator fun plus(c: Complex): Complex {

return (Complex(c.x + x, c.y + y))

}



}
Collections
❖ no language operators for construction of lists and maps
❖ using underlying java collections
❖ Have two versions mutable and immutable
❖ Immutability is a lie at least ATM it is only an immutable
view of a mutable collection.
Collections
val chars = mapOf("Terion" to "Lannister", "John" to "Snow")

chars["Terion"]

chars["Aria"] = “Stark"




val chars2 = mutableMapOf<String,String>()

chars2["A girl"] = "has no name"



val sigils = listOf("Direwolf", "Lion", "Dragon", "Flower")

println(sigils[0])
Kotlin 1.1
❖ Java 7/8 support -> generate J8 class files
❖ Coroutines : async / await (stackless continuations)
❖ Generators: Yield
❖ inheritance of data classes
Generators (yield)
val fibonacci: Sequence<Int> = generate {
yield(1) // first Fibonacci number
var cur = 1
var next = 1
while (true) {
yield(next) // next Fibonacci number
val tmp = cur + next
cur = next
next = tmp
}
}
Questions?

More Related Content

PDF
Building microservices with Kotlin
Haim Yadid
 
PDF
Coding for Android on steroids with Kotlin
Kai Koenig
 
PDF
Swift and Kotlin Presentation
Andrzej Sitek
 
PDF
Kotlin boost yourproductivity
nklmish
 
PDF
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
PDF
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
PDF
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
PDF
Kotlin - Better Java
Dariusz Lorenc
 
Building microservices with Kotlin
Haim Yadid
 
Coding for Android on steroids with Kotlin
Kai Koenig
 
Swift and Kotlin Presentation
Andrzej Sitek
 
Kotlin boost yourproductivity
nklmish
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Hardik Trivedi
 
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Kotlin, smarter development for the jvm
Arnaud Giuliani
 
Kotlin - Better Java
Dariusz Lorenc
 

What's hot (20)

PDF
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
PDF
Introduction to kotlin
NAVER Engineering
 
PDF
2017: Kotlin - now more than ever
Kai Koenig
 
PDF
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan s.r.o.
 
PPT
The Kotlin Programming Language
intelliyole
 
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
PDF
Kotlin: Why Do You Care?
intelliyole
 
PDF
Kotlin in action
Ciro Rizzo
 
PDF
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 
PPTX
K is for Kotlin
TechMagic
 
PPTX
Introduction to kotlin + spring boot demo
Muhammad Abdullah
 
PDF
Kotlin Overview
Silicon Straits
 
PDF
Kotlin: Challenges in JVM language design
Andrey Breslav
 
PDF
No excuses, switch to kotlin
Thijs Suijten
 
PDF
A quick and fast intro to Kotlin
XPeppers
 
PDF
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
PDF
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
PDF
Kotlin for Android - Vali Iorgu - mRready
MobileAcademy
 
PPTX
Kotlin
Rory Preddy
 
PDF
Summer of Tech 2017 - Kotlin/Android bootcamp
Kai Koenig
 
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Introduction to kotlin
NAVER Engineering
 
2017: Kotlin - now more than ever
Kai Koenig
 
eMan Dev Meetup: Kotlin - A Language we should know it exists (part 02/03) 18...
eMan s.r.o.
 
The Kotlin Programming Language
intelliyole
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Arnaud Giuliani
 
Kotlin: Why Do You Care?
intelliyole
 
Kotlin in action
Ciro Rizzo
 
Kotlin hands on - MorningTech ekito 2017
Arnaud Giuliani
 
K is for Kotlin
TechMagic
 
Introduction to kotlin + spring boot demo
Muhammad Abdullah
 
Kotlin Overview
Silicon Straits
 
Kotlin: Challenges in JVM language design
Andrey Breslav
 
No excuses, switch to kotlin
Thijs Suijten
 
A quick and fast intro to Kotlin
XPeppers
 
Kotlin Slides from Devoxx 2011
Andrey Breslav
 
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
Kotlin for Android - Vali Iorgu - mRready
MobileAcademy
 
Kotlin
Rory Preddy
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Kai Koenig
 
Ad

Viewers also liked (16)

PDF
The Future of Futures - A Talk About Java 8 CompletableFutures
Haim Yadid
 
PDF
Kotlin в production. Как и зачем?
DotNetConf
 
PDF
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
Haim Yadid
 
PPTX
#MBLTdev: Kotlin для Android, или лёгкий способ перестать программировать на ...
e-Legion
 
PDF
Tales About Scala Performance
Haim Yadid
 
PDF
mjprof: Monadic approach for JVM profiling
Haim Yadid
 
PDF
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
PDF
The Wix Microservice Stack
Tomer Gabel
 
PDF
Java 8 Launch - MetaSpaces
Haim Yadid
 
PPTX
A topology of memory leaks on the JVM
Rafael Winterhalter
 
PPTX
ClassLoader Leaks
Mattias Jiderhamn
 
PPTX
The Java Memory Model
CA Technologies
 
PDF
Let's talk about Garbage Collection
Haim Yadid
 
PDF
Building Scalable Stateless Applications with RxJava
Rick Warren
 
PPTX
Memory Management: What You Need to Know When Moving to Java 8
AppDynamics
 
PPTX
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
Stephen Chin
 
The Future of Futures - A Talk About Java 8 CompletableFutures
Haim Yadid
 
Kotlin в production. Как и зачем?
DotNetConf
 
JVM Garbage Collection logs, you do not want to ignore them! - Reversim Summi...
Haim Yadid
 
#MBLTdev: Kotlin для Android, или лёгкий способ перестать программировать на ...
e-Legion
 
Tales About Scala Performance
Haim Yadid
 
mjprof: Monadic approach for JVM profiling
Haim Yadid
 
Kotlin Bytecode Generation and Runtime Performance
intelliyole
 
The Wix Microservice Stack
Tomer Gabel
 
Java 8 Launch - MetaSpaces
Haim Yadid
 
A topology of memory leaks on the JVM
Rafael Winterhalter
 
ClassLoader Leaks
Mattias Jiderhamn
 
The Java Memory Model
CA Technologies
 
Let's talk about Garbage Collection
Haim Yadid
 
Building Scalable Stateless Applications with RxJava
Rick Warren
 
Memory Management: What You Need to Know When Moving to Java 8
AppDynamics
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
Stephen Chin
 
Ad

Similar to Taking Kotlin to production, Seriously (20)

PDF
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
PDF
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
Andrey Breslav
 
PDF
Privet Kotlin (Windy City DevFest)
Cody Engel
 
PDF
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
PDF
Intro to Kotlin
Magda Miu
 
PPTX
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
PPTX
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
PDF
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
PDF
Kotlin @ Devoxx 2011
Andrey Breslav
 
PDF
Bologna Developer Zone - About Kotlin
Marco Vasapollo
 
PPTX
Intro to kotlin 2018
Shady Selim
 
PDF
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
PDF
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
PPTX
Kotlin Language Features - A Java comparison
Ed Austin
 
PDF
Kotlin intro
Elifarley Cruz
 
PPTX
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
PDF
Comparing JVM languages
Jose Manuel Ortega Candel
 
PPTX
Kotlin presentation
MobileAcademy
 
PDF
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
PDF
Kotlin for Android devs
Adit Lal
 
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
Andrey Breslav
 
Privet Kotlin (Windy City DevFest)
Cody Engel
 
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 
Intro to Kotlin
Magda Miu
 
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Why Kotlin is your next language?
Aliaksei Zhynhiarouski
 
Kotlin @ Devoxx 2011
Andrey Breslav
 
Bologna Developer Zone - About Kotlin
Marco Vasapollo
 
Intro to kotlin 2018
Shady Selim
 
Is this Swift for Android? A short introduction to the Kotlin language
Antonis Lilis
 
Kotlin: forse è la volta buona (Trento)
Davide Cerbo
 
Kotlin Language Features - A Java comparison
Ed Austin
 
Kotlin intro
Elifarley Cruz
 
Hello kotlin | An Event by DSC Unideb
Muhammad Raza
 
Comparing JVM languages
Jose Manuel Ortega Candel
 
Kotlin presentation
MobileAcademy
 
A short introduction to the Kotlin language for Java developers
Antonis Lilis
 
Kotlin for Android devs
Adit Lal
 

More from Haim Yadid (13)

PDF
On-Call AI Assistant: Streamlining Production Error Investigation with LLM
Haim Yadid
 
PDF
Loom me up Scotty! Project Loom - What's in it for Me?
Haim Yadid
 
PDF
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
PDF
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Haim Yadid
 
PPTX
“Show Me the Garbage!”, Understanding Garbage Collection
Haim Yadid
 
PDF
Java Memory Structure
Haim Yadid
 
PDF
Basic JVM Troubleshooting With Jmx
Haim Yadid
 
PDF
The Freelancer Journey
Haim Yadid
 
PDF
Java 8 - Stamped Lock
Haim Yadid
 
PDF
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
PDF
A short Intro. to Java Mission Control
Haim Yadid
 
PDF
Java Enterprise Edition Concurrency Misconceptions
Haim Yadid
 
PDF
Israeli JUG - IL JUG presentation
Haim Yadid
 
On-Call AI Assistant: Streamlining Production Error Investigation with LLM
Haim Yadid
 
Loom me up Scotty! Project Loom - What's in it for Me?
Haim Yadid
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
Kotlin Backend Development 6 Yrs Recap. The Good, the Bad and the Ugly
Haim Yadid
 
“Show Me the Garbage!”, Understanding Garbage Collection
Haim Yadid
 
Java Memory Structure
Haim Yadid
 
Basic JVM Troubleshooting With Jmx
Haim Yadid
 
The Freelancer Journey
Haim Yadid
 
Java 8 - Stamped Lock
Haim Yadid
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
A short Intro. to Java Mission Control
Haim Yadid
 
Java Enterprise Edition Concurrency Misconceptions
Haim Yadid
 
Israeli JUG - IL JUG presentation
Haim Yadid
 

Recently uploaded (20)

PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PPTX
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
slidesgo-unlocking-the-code-the-dynamic-dance-of-variables-and-constants-2024...
kr2589474
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Immersive experiences: what Pharo users do!
ESUG
 

Taking Kotlin to production, Seriously

  • 1. Haim Yadid / Next Insurance mapOf( taking?. kotlin to production ) Seriously!!
  • 2. Disclaimer ‫בה‬ ‫לנאמר‬ ‫לייחס‬ ‫ואין‬ ‫סאטירה‬ ‫תוכנית‬ ‫הינה‬ ‫זו‬ ‫תוכנית‬ ‫כלשהי‬ ‫תכנות‬ ‫בשפת‬ ‫לפגוע‬ ‫ניסיון‬ ‫או‬ ‫אחרת‬ ‫משמעות‬ ‫שום‬ ‫בה‬ ‫המופיעים‬ ‫מהתכנים‬ ‫נפגע‬ ‫חש‬ ‫הנך‬ ‫זאת‬ ‫בכל‬ ‫אם‬ ‫מראש‬ ‫מתנצלים‬ ‫אנו‬ ‫בסקאלה‬ ‫מתכנת‬ ‫אתה‬ ‫אם‬ ‫או‬
  • 3. About Me ❖ Developing software since 1984 (Boy, am I getting old?) ❖ Basic -> Pascal -> C -> C++ -> Java -> Kotlin ❖ Architect in Mercury ❖ Independent performance expert for 7 years ❖ Backend developer in
  • 4. ❖ Founded in the Beginning of 2016 ❖ HQ@Palo Alto RnD@Kfar Saba ❖ Aims to disrupt the Small businesses insurance field ❖ Providing online experience which is simple fast and transparent ❖ We started to write real code on May 2016
  • 6. What is Kotlin ? ❖ Statically typed programming language ❖ for the JVM, Android and the browser (JS) ❖ 100% interoperable with Java™ (well almost) ❖ Developed by Jetbrains ❖ Revealed as an open source in July 2011 ❖ v1.0 Release on Feb 2016 ❖ 1.0.5 current stable version (28.11.2016)
  • 7. Kotlin Features ❖ Concise ❖ Safe ❖ Versatile ❖ Practical ❖ Interoperable
  • 8. Why Kotlin Java Scala Cloju Groovy/ JRuby Java8 Strongly
 Typed Loosely
 Typed OO/verbose Functional/Rich )))))))))))))))))))))))))))))))
  • 9. Why Kotlin Java Scala Cloju Groovy/ JRuby Java8 Strongly
 Typed Loosely
 Typed OO/verbose Functional/Rich Kotlin )))))))))))))))))))))))))))))))
  • 10. Scala can do it !! ? ❖ Yes Scala can do it ❖ Academic / Complicated ❖ Scala compile time is horrific ❖ Operator overloading -> OMG
  • 11. Getting Started ❖ Kotlin has very lightweight standard library ❖ Mostly rely on Java collections for good (interop) and for bad (all the rest) ❖ Kotlin compiles to Java6 byte code ❖ Has no special build tool just use Maven / Gradle
  • 12. Kotlin & Android ❖ Kotlin got widely accepted on the android community ❖ Runtime has low footprint ❖ Compiles to …. Java 6 ❖ Brings lambdas to Android dev and a lot of cool features
  • 13. Trivial Stuff ❖ No new keyword ❖ No checked exceptions ❖ == structural equality ❖ === referencial equality ❖ No primitives (only under the hood) ❖ No arrays they are classes ❖ Any ~ java.lang.Object
  • 14. Fun ❖ Functions are denoted with the fun keyword ❖ They can be member of a class ❖ Or top level functions inside a kotlin file ❖ can support tail recursion ❖ can be inlined ❖ fun funny(funnier: String) = "Hello world"
  • 15. Fun Parameters ❖ Pascal notation ❖ Function parameters may have default values ❖ Call to function can be done using parameter names fun mergeUser(first: String = "a", last: String) = first + last
 
 fun foo() {
 mergeUser(first="Albert",last= "Einstein")
 mergeUser(last= "Einstein")
 }
  • 16. Extension functions ❖ Not like ruby monkey patching ❖ Only extend functionality cannot override ❖ Not part of the class ❖ Static methods with the receiver as first a parameter fun String.double(sep: String) = "$this$sep$this"
  • 17. ❖ variables are declared using the keywords ❖ val (immutable) ❖ var (mutable) ❖ fun funny(funnier: String): String {
 val x = "Hello world"
 return x
 } val /var
  • 18. Classes ❖ less verbose than Java ❖ no static members (use companion object) ❖ public is default ❖ Must be declared open to be overridden ❖ override keyword is mandatory class Producer(val name:String, val value: Int)
  • 19. Properties ❖ All members of classes are access via proper accessors (getter and setters) ❖ The usage of getters and setters is implicit ❖ one can override implementation of setters and getters
  • 20. Delegate Class interface Foo {
 fun funfun()
 }
 
 class FooImpl(val x: Int) : Foo {
 override fun funfun() = print(x)
 }
 
 class Wrapper(f: Foo) : Foo by f
 
 fun main(args: Array<String>) {
 val f = FooImpl(10)
 val wf = Wrapper(f)
 wf.funfun() // prints 10
 }
  • 21. Smart Casts ❖ If you check that a class is of a certain type no need to cast it open class A {
 fun smile() { println(":)")}
 }
 
 class B : A() {
 fun laugh() = println("ha ha ha")
 }
 
 fun funnier(a: A) {
 if (a is B ) {
 a.laugh()
 }
 }
  • 22. Null Safety ❖ Nullability part of the type of an object ❖ Option[T] Optional<T> ❖ Swift anyone ? var msg : String = "Welcome"
 msg = null val nullableMsg : String? = null
  • 23. Safe operator ?. ❖ The safe accessor operator ?. will result null ❖ Elvis operator for default fun funny(funnier: String?): Int? {
 
 println(x?.length ?: "")
 return x?.length
 }
  • 24. Bang Bang !! ❖ The bang bang !! throws an NPE if object is null fun funny(funnier: String?): String {
 return funnier!!
 }
  • 25. Data classes ❖ Less powerful version of to case classes in Scala ❖ Implementation of ❖ hashcode() equals() ❖ copy() ❖ de structuring (component1 component2 …) data class User(val firstName: String, val lastName: String)
 
 fun smile(user: User) {
 val (first,last) = user
 }
  • 26. When ❖ Reminds Scala’s pattern matching but not as strong ❖ More capable than select in java when (x) {
 is Int -> print(x + 1)
 is String -> print(x.length + 1)
 is IntArray -> print(x.sum())
 }
  • 27. Sane Operator Overloading ❖ override only a set of the predefined operators ❖ By implementing the method with the correct name Expression Translated to a + b a.plus(b) a - b a.minus(b) a * b a.times(b) a / b a.div(b) a % b a.mod(b) a..b a.rangeTo(b)
  • 28. Sane Operator Overloading data class Complex(val x: Double, val y: Double) {
 operator fun inc(): Complex {
 return Complex(x + 1, y + 1)
 }
 
 infix operator fun plus(c: Complex): Complex {
 return (Complex(c.x + x, c.y + y))
 }
 
 }
  • 29. Collections ❖ no language operators for construction of lists and maps ❖ using underlying java collections ❖ Have two versions mutable and immutable ❖ Immutability is a lie at least ATM it is only an immutable view of a mutable collection.
  • 30. Collections val chars = mapOf("Terion" to "Lannister", "John" to "Snow")
 chars["Terion"]
 chars["Aria"] = “Stark" 
 
 val chars2 = mutableMapOf<String,String>()
 chars2["A girl"] = "has no name"
 
 val sigils = listOf("Direwolf", "Lion", "Dragon", "Flower")
 println(sigils[0])
  • 31. Kotlin 1.1 ❖ Java 7/8 support -> generate J8 class files ❖ Coroutines : async / await (stackless continuations) ❖ Generators: Yield ❖ inheritance of data classes
  • 32. Generators (yield) val fibonacci: Sequence<Int> = generate { yield(1) // first Fibonacci number var cur = 1 var next = 1 while (true) { yield(next) // next Fibonacci number val tmp = cur + next cur = next next = tmp } }