SlideShare a Scribd company logo
1 of 40
Download to read offline
Why Kotlin is your next
language?
theory and practice
Aliaksei Zhynhiarouski
1
Dev Day MiniQ, 2016
Kotlin Island
2
Why is Kotlin
• Static Typing bit.ly/st-vs-dyn
• Java + Kotlin = ❤. 

Effortless mixing both in one project
• Java Interoperability. 

100% interoperable with Java.
3
Why is Kotlin
• Null Safety
• Type Inference
• Immutability in the mind
• fun
4
fun main(args : Array<String>) {
println("Hello, MiniQ!")
}
5
val from_value : Type
var from_variable : Type
val i_am_string = “mobile”
var i_am_long = 666L
val i_am_double = 3.14e10
6
val & var
Null Safety
// can’t be null

val foo: String = “Dev Day”


// need always perform the check 

val bar: String? = null
7
Type? = Type or null
Null Safety
val bar: String? = “Dev Day”


var a = bar?.length // 6



var b = bar?.length?.inc() // 7



var c = bar!!.length // can be NPE
8
Null Safety
val bar: String? = null


var a = if (bar != null) bar.length

else 0 // 0



var b = bar?.length ?: 0 // 0

9
Type Definition
class Phone(val brand: String)
10
• concise syntax for constructor
• properties – not fields
• final by default. Use open to open
• simple old java class under the hood
Type Definition
class Phone(val brand: String){
var version: Int = 0
}
11
get() {…}

private set
val phone = Phone(“Apple”)

phone.brand == “Apple” // true
Value Object
data class Phone(val brand: String)
12
toString()
hashCode()
equals()

copy()
Get ready to be inspired
13
Extensions
14
// Usage Example



“MiniQ”.lastChar() // “Q”

// Definition



fun String.lastChar():Char 

= this.get(length - 1)
Extensions
15
// Java under the hood



@file:JvmName(“StringUtils")

StringUtils.lastChar(“Mobile”);
Extensions
16
Collections.max(list)



↓
list.max()
Extensions
17
operator fun BigDecimal.inc() 

= this + BigDecimal.ONE


// Example

var counter = BigDecimal.ZERO



print(++counter) // 1
Extensions
18
“25”.toInt() // Int
“8.$minor.5”.toOsVersion() // to object
Android Extensions
19
val text = find<TextView>(R.id.text)
Just extend Activity and have fun
inline fun <reified T : View> 

Activity.find(id: Int): T = this.findViewById(id) as T
final TextView text = (TextView) v.findViewById(R.id.text);
Lambdas
20
val boys = listOf(

Boy(“Alex”), Boy(“Petr”), Boy(“Oleg”))

// 1 

boys.filter({ b: Boy -> b.age > 18 })

// 2

boys.filter({ it.age > 18 })


// 3

boys.filter { it.age > 18 }
λ
21
boys.filter { it.age > 18 }
.map { Pair(it, Boy("Eugene")) }
.forEach { dance(it) }
// Definition



inline fun <T> Iterable<T>.filter

(predicate: (T) -> Boolean)

λ
22
db.inTransaction {

delete(“users”, “name = ?”, arrayOf(“Alex”))

}
fun SQLiteDatabase.inTransaction(func: SQLiteDatabase.() -> Unit) {
beginTransaction()
try {

func()

setTransactionSuccessful()
} finally {
endTransaction()
}
}
Delegates – right way
23
class View {















}
val lazyProp by lazy { “Dev Day” }
val ops by observable(“”) { 

prop, old, new ->
print("$old to $new")
}
Delegates – wow way
24
class Activity {













}
private val btn: Button by lazy {

findViewById(R.id.btn) as Button

}



override fun onCreate(savedBundle: Bundle?) {

btn.setText(“MiniQ!”)

}


Delegates – wow way
25
class Query(val props: Map<String, String>) {



}
val category by props

val model by props



val info: String

get() {

return “$category - $model” 

}
Delegates – wow way
26
class Query(val props: Map<String, String>) {



}
val category by props

val model by props

…

val props = mapOf(“category” to “XXX”,

“model” to “YYY”)

val query = Query(props)
print(query.info) // “XXX - YYY”

DSL
27
• Type-safe
• Express your code by flexible syntax
• Ideal to build own query engine
• if/for/when just inside DSL
DSL
28
"(#C1 = :active) AND (#C2 = :type) AND " +
"(attribute_not_exists(#C1) OR #C1 IN
(:model, :allModels)) AND " +

"...";

if (smth)

append("(#C2 = :active) AND NOT
contains(#C3, :brandAll)");
…
// wait, oh shi~
DSL
29
val expr = filterExpr {

group {

eq("#1", ":2") and eq("#1", ":2") 

or group {

eq("#2", ":2")

if (smth) { 

and eq("#2", ":2") 

}

}

and ……

}
One more DSL thing
30
Gradle 3 meets Kotlin
Kotlin 1.1
typealias Callback<T> = (T) -> T
// And now

fun alias(cb: Callback<String>) {}
31
Type aliases
Kotlin 1.1
typealias Table<K> = 



MutableMap<K, MutableList<String>>
32
Type aliases
Kotlin 1.1
val future = async<String> {
(1..5).map {
await(loooongAsyncOperation(it))



}.joinToString("n")
}
33
Coroutines with async/await
Why is Kotlin
• Use all existing Java frameworks and
libraries
• Code reviews are not a problem
• Suitable for enterprise Java
• Adopting is low risk
34
Why is Kotlin
• Android
• Gradle
• Can be learned in a few hours
• Kotlin also compiles to JavaScript ;)
35
http://try.kotl.in
36
Links
Awesome Kotlin kotlin.link
Slack kotlinlang.slack.com 

Local’s Chat gitter.im/JavaBy/Kotlin

37
Links just for you
Kotlin compilation speed

Performance: Kotlin Bytecode
https://www.youtube.com/watch?v=eQ4YHpAXdp4

Experience of Square with Kotlin. Good analysis

Android Development advanced

https://vimeo.com/144877458

Kotlin in real project with a lot of nuances

https://www.youtube.com/watch?v=CABN2r4GPpQ
38
Kotlin friends
39
jprof.by
bkug.by
Go v Minsk, ja sozdal

More Related Content

What's hot

What's hot (20)

Elm introduction
Elm   introductionElm   introduction
Elm introduction
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures edition
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
 
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9Simulator customizing & testing for Xcode 9
Simulator customizing & testing for Xcode 9
 
C++ Programming - 5th Study
C++ Programming - 5th StudyC++ Programming - 5th Study
C++ Programming - 5th Study
 
Kotlin
KotlinKotlin
Kotlin
 
The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
Kotlin Backstage
Kotlin BackstageKotlin Backstage
Kotlin Backstage
 
dplyr
dplyrdplyr
dplyr
 
미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정미려한 UI/UX를 위한 여정
미려한 UI/UX를 위한 여정
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 

Similar to Why Kotlin is your next language?

ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
Bartosz Kosarzycki
 

Similar to Why Kotlin is your next language? (20)

Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
 
Android 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutesAndroid 101 - Building a simple app with Kotlin in 90 minutes
Android 101 - Building a simple app with Kotlin in 90 minutes
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)
 
Kotlin 101 for Java Developers
Kotlin 101 for Java DevelopersKotlin 101 for Java Developers
Kotlin 101 for Java Developers
 
Effective Object Oriented Design in Cpp
Effective Object Oriented Design in CppEffective Object Oriented Design in Cpp
Effective Object Oriented Design in Cpp
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018 Meetup di GDG Italia - Leonardo Pirro -  Codemotion Rome 2018
Meetup di GDG Italia - Leonardo Pirro - Codemotion Rome 2018
 
ADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developersADG Poznań - Kotlin for Android developers
ADG Poznań - Kotlin for Android developers
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguajeKotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
 
Intro to kotlin 2018
Intro to kotlin 2018Intro to kotlin 2018
Intro to kotlin 2018
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Why Kotlin is your next language?

  • 1. Why Kotlin is your next language? theory and practice Aliaksei Zhynhiarouski 1 Dev Day MiniQ, 2016
  • 3. Why is Kotlin • Static Typing bit.ly/st-vs-dyn • Java + Kotlin = ❤. 
 Effortless mixing both in one project • Java Interoperability. 
 100% interoperable with Java. 3
  • 4. Why is Kotlin • Null Safety • Type Inference • Immutability in the mind • fun 4
  • 5. fun main(args : Array<String>) { println("Hello, MiniQ!") } 5
  • 6. val from_value : Type var from_variable : Type val i_am_string = “mobile” var i_am_long = 666L val i_am_double = 3.14e10 6 val & var
  • 7. Null Safety // can’t be null
 val foo: String = “Dev Day” 
 // need always perform the check 
 val bar: String? = null 7 Type? = Type or null
  • 8. Null Safety val bar: String? = “Dev Day” 
 var a = bar?.length // 6
 
 var b = bar?.length?.inc() // 7
 
 var c = bar!!.length // can be NPE 8
  • 9. Null Safety val bar: String? = null 
 var a = if (bar != null) bar.length
 else 0 // 0
 
 var b = bar?.length ?: 0 // 0
 9
  • 10. Type Definition class Phone(val brand: String) 10 • concise syntax for constructor • properties – not fields • final by default. Use open to open • simple old java class under the hood
  • 11. Type Definition class Phone(val brand: String){ var version: Int = 0 } 11 get() {…}
 private set val phone = Phone(“Apple”)
 phone.brand == “Apple” // true
  • 12. Value Object data class Phone(val brand: String) 12 toString() hashCode() equals()
 copy()
  • 13. Get ready to be inspired 13
  • 14. Extensions 14 // Usage Example
 
 “MiniQ”.lastChar() // “Q”
 // Definition
 
 fun String.lastChar():Char 
 = this.get(length - 1)
  • 15. Extensions 15 // Java under the hood
 
 @file:JvmName(“StringUtils")
 StringUtils.lastChar(“Mobile”);
  • 17. Extensions 17 operator fun BigDecimal.inc() 
 = this + BigDecimal.ONE 
 // Example
 var counter = BigDecimal.ZERO
 
 print(++counter) // 1
  • 19. Android Extensions 19 val text = find<TextView>(R.id.text) Just extend Activity and have fun inline fun <reified T : View> 
 Activity.find(id: Int): T = this.findViewById(id) as T final TextView text = (TextView) v.findViewById(R.id.text);
  • 20. Lambdas 20 val boys = listOf(
 Boy(“Alex”), Boy(“Petr”), Boy(“Oleg”))
 // 1 
 boys.filter({ b: Boy -> b.age > 18 })
 // 2
 boys.filter({ it.age > 18 }) 
 // 3
 boys.filter { it.age > 18 }
  • 21. λ 21 boys.filter { it.age > 18 } .map { Pair(it, Boy("Eugene")) } .forEach { dance(it) } // Definition
 
 inline fun <T> Iterable<T>.filter
 (predicate: (T) -> Boolean)

  • 22. λ 22 db.inTransaction {
 delete(“users”, “name = ?”, arrayOf(“Alex”))
 } fun SQLiteDatabase.inTransaction(func: SQLiteDatabase.() -> Unit) { beginTransaction() try {
 func()
 setTransactionSuccessful() } finally { endTransaction() } }
  • 23. Delegates – right way 23 class View {
 
 
 
 
 
 
 
 } val lazyProp by lazy { “Dev Day” } val ops by observable(“”) { 
 prop, old, new -> print("$old to $new") }
  • 24. Delegates – wow way 24 class Activity {
 
 
 
 
 
 
 } private val btn: Button by lazy {
 findViewById(R.id.btn) as Button
 }
 
 override fun onCreate(savedBundle: Bundle?) {
 btn.setText(“MiniQ!”)
 } 

  • 25. Delegates – wow way 25 class Query(val props: Map<String, String>) {
 
 } val category by props
 val model by props
 
 val info: String
 get() {
 return “$category - $model” 
 }
  • 26. Delegates – wow way 26 class Query(val props: Map<String, String>) {
 
 } val category by props
 val model by props
 …
 val props = mapOf(“category” to “XXX”,
 “model” to “YYY”)
 val query = Query(props) print(query.info) // “XXX - YYY”

  • 27. DSL 27 • Type-safe • Express your code by flexible syntax • Ideal to build own query engine • if/for/when just inside DSL
  • 28. DSL 28 "(#C1 = :active) AND (#C2 = :type) AND " + "(attribute_not_exists(#C1) OR #C1 IN (:model, :allModels)) AND " +
 "...";
 if (smth)
 append("(#C2 = :active) AND NOT contains(#C3, :brandAll)"); … // wait, oh shi~
  • 29. DSL 29 val expr = filterExpr {
 group {
 eq("#1", ":2") and eq("#1", ":2") 
 or group {
 eq("#2", ":2")
 if (smth) { 
 and eq("#2", ":2") 
 }
 }
 and ……
 }
  • 30. One more DSL thing 30 Gradle 3 meets Kotlin
  • 31. Kotlin 1.1 typealias Callback<T> = (T) -> T // And now
 fun alias(cb: Callback<String>) {} 31 Type aliases
  • 32. Kotlin 1.1 typealias Table<K> = 
 
 MutableMap<K, MutableList<String>> 32 Type aliases
  • 33. Kotlin 1.1 val future = async<String> { (1..5).map { await(loooongAsyncOperation(it))
 
 }.joinToString("n") } 33 Coroutines with async/await
  • 34. Why is Kotlin • Use all existing Java frameworks and libraries • Code reviews are not a problem • Suitable for enterprise Java • Adopting is low risk 34
  • 35. Why is Kotlin • Android • Gradle • Can be learned in a few hours • Kotlin also compiles to JavaScript ;) 35
  • 38. Links just for you Kotlin compilation speed Performance: Kotlin Bytecode https://www.youtube.com/watch?v=eQ4YHpAXdp4 Experience of Square with Kotlin. Good analysis Android Development advanced https://vimeo.com/144877458 Kotlin in real project with a lot of nuances https://www.youtube.com/watch?v=CABN2r4GPpQ 38
  • 40. Go v Minsk, ja sozdal