Through this event, we aimed to educate you on the basics and fundamentals of Kotlin.
->How to get started?
->What are its benefits?
This event was EVERYTHING KOTLIN!!
10. 2016 2017 2018 2019 2020
1.0 Google I/O: Kotlin Officially supported language for Android
Kotlin Timeline
11. 2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
Kotlin Timeline
12. 2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
Coroutines Preferred
Kotlin Timeline
13. Kotlin Timeline
2016 2017 2018 2019 2020
1.0
Google I/O: Kotlin Officially supported language for Android
Google I/O: Android goes Kotlin-first
You are here
Coroutines Preferred
15. - Google Preferred Language
- Statistically typed
- Type Inference
- Developed by Jetbrains
- Concise
- 100% interoperable with Java
- Null Safety
- And many more.
37. 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.
38. 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
39. Swift is like Kotlin:
Hello World
Swift
print("Hello, world!")
Kotlin
println("Hello, world!")
40. Swift
var myVariable = 42
myVariable = 50
let myConstant = 42
Kotlin
var myVariable = 42
myVariable = 50
val myConstant = 42
Swift is like Kotlin:
Variables And Constants
42. 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"
Swift is like Kotlin:
Arrays
43. 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")
Swift is like Kotlin:
Functions
44. 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."
}
Swift is like Kotlin:
Classes
45. • Advantages over Java 7 are overwhelming
• Java 8 introduced
• Lambdas
• Null safety (“Optional” class)
• Default methods
• Streams API
• New Date & Time API
Java strikes back with Java 8
46. • Is more elegant, concise and safe
• Has more cool stuff
But even with Java 8 Kotlin still...
47.
48. • Functions - definition in package or in class
• Immutable/mutable variables
• No “new” keyword
• Type inference
• No checked exceptions
• No primitive types
• No static members
Basic syntax and rules
More elegant?
49. • Primary constructors
• No fields, just properties
• Bean style classes easy to declare
• By default, all classes are final
Basic syntax and rules cont’d
More elegant?
50. • Null reference – Billion dollar mistake
• Kotlin is designed in a way that aims to eliminate NPE from our code
Null Safety
More elegant?
Tony Hoare
51. • Declaration-site variance
• out / in generics modifiers
• Supports use-site variance also
• No wildcard syntax, out / in used
Generics
More elegant?
53. • Default argument values can be defined
• Arguments with default values are optional
• No more need for function overloading (almost)
• Kotlin classes can have only one constructor
• Arguments can be called by name
• When passing arguments by name ordering doesn’t matter
Default arguments and
named arguments
54. • Simpler “is it in range” check
• Can be used for any type that implements Comparable
• “both ends“ included
• “..” operator is translated to “rangeTo” function
• “rangeTo” function is implemented as extension function on
Comparable
• Numerical ranges can be iterated over
• In both directions and in arbitrary steps
Ranges
56. • Java’s instaceof not very practical
• No !instanceof
• Meet Kotlin’s "is“
• "is" negation "!is“
• Automatic type cast when “is” evaluates true inside if / when
blocks
Pattern matching