@ArbazPirwani
WHY KOTLIN?
- Google Preferred Language
- Statistically typed
- Type Inference
- Developed by Jetbrains
- Concise
- 100% interoperable with Java
- Null Safety
- And many more.
A modern programming language
that makes developers happier.
Kotlin Timeline
2016 2017 2018 2019 2020 2021
Kotlin Timeline
1.0
2016 2017 2018 2019 2020 2021
Kotlin Timeline
1.0 Google I/O: Kotlin Officially supported language for Android
2016 2017 2018 2019 2020 2021
Kotlin Timeline
1.0 Google I/O: Kotlin Officially supported language for Android Google I/O: Android goes Kotlin-first
2016 2017 2018 2019 2020 2021
Kotlin Timeline
1.0 Google I/O: Kotlin Officially supported language for Android Google I/O: Android goes Kotlin-first
Coroutines Preferred
2016 2017 2018 2019 2020 2021
Java vs Kotlin
Java to Kotlin
Server
Kotlin/JVM
Android
Kotlin/JVM
iOS Browser
Kotlin/Native Kotlin/JS
● Data Classes ● Type Inference
● Extension Methods ● DSL Support
● Elvis Operator ● Type-Safe Builders
● Properties ● Coroutines
Default Parameters String Interpolation
Coroutines
● ●
● Type Aliases ● Ranges
● Named Parameters ● Map Array Syntax
● Spread Operator ● Inline Functions
● Auto Casts ● Sealed Classes
● Covariance ● Delegation
● Null Safety ● Destructuring
● Operator Overloading ● KDoc
Coroutines
● Coroutines are like very light-weight threads
● Asynchronous programming made easy
● No callbacks
● No complex functionality
VS
Kotlin & Swift
● The syntax of Swift doesn’t just resemble that of Kotlin: in
small chunks of code there can be up to 77% string
similarity.
● At the very least, it should be noted that while Swift
appeared in 2013, Kotlin originated back in 2011. Hence,
even though comparing Kotlin to Swift (in this exact order)
can be convenient due to Swift’s earlier introduction to a
wide audience, any ‘copycat’ attitudes towards Kotlin
aren’t justified.
Kotlin & Swift
● Available on both mobile-client and back-end server
● Highly performant and statically-typed
● Kotlin also can be used for web front-end via Kotlin.JS
Swift is like Kotlin:
Hello World
Swift
print("Hello, world!")
Kotlin
println("Hello, world!")
Source: http://nilhcem.com/swift-is-like-kotlin/
Swift is like Kotlin:
Variables And Constants
Swift
var myVariable = 42
myVariable = 50
let myConstant = 42
Kotlin
var myVariable = 42
myVariable = 50
val myConstant = 42
Source: http://nilhcem.com/swift-is-like-kotlin/
Swift is like Kotlin:
Explicit Types
Swift
let explicitDouble: Double = 42
Kotlin
val explicitDouble: Double = 42.0
Source: http://nilhcem.com/swift-is-like-kotlin/
Swift is like Kotlin:
Arrays
Swift
var shoppingList = ["catfish", "water","tulips", "blue paint"]
shoppingList[1] = "bottle of water"
Kotlin
val shoppingList = arrayOf("catfish", "water","tulips", "blue paint")
shoppingList[1] = "bottle of water"
Source: http://nilhcem.com/swift-is-like-kotlin/
Swift is like Kotlin:
Functions
Swift
func greet(_ name: String,_ day: String) -> String {
return "Hello \(name), today is \(day)."
}
greet("Bob", "Tuesday")
Kotlin
fun greet(name: String, day: String): String {
return "Hello $name, today is $day."
}
greet("Bob", "Tuesday")
Source: http://nilhcem.com/swift-is-like-kotlin/
Swift is like Kotlin:
Classes
Swift
class Shape {
var numberOfSides = 0
func simpleDescription() -> String {
return "A shape with \(numberOfSides) sides."
}
}
Kotlin
class Shape {
var numberOfSides = 0
fun simpleDescription() = "A shape with $numberOfSides sides."
}
Source: http://nilhcem.com/swift-is-like-kotlin/
Java strikes back with Java 8
• Advantages over Java 7 are overwhelming
• Java 8 introduced
• Lambdas
• Null safety (“Optional” class)
• Default methods
• Streams API
• New Date & Time API
But even with Java 8 Kotlin still...
• Is more elegant, concise and safe
• Has more cool stuff
MORE COOL STUFF