3. ThoughtWorks Radar
- Adopt
Bekk Consulting Radar
- Adopt
Kotlin has experienced an accelerated rate of adoption and
rapid growth of tooling support. (…) reasons behind its
popularity are its concise syntax, null safety, ease of transition from Java
and interoperability with other JVM-based languages in general
Vi mener at Kotlin gjør mye riktig og er et godt alternativ eller
supplement til Java, samtidig som terskelen for å bruke
det er lav. Java-utviklere vil raskt kunne sette seg inn i en kodebase
skrevet i Kotlin og fordelene ved å starte å bruke Kotlin er verdt det.
4. Nullable types
-Tony Hoare
“I call it my billion-dollar mistake. It was the
invention of the null reference in 1965.”
5. var s1: String = "abc"
s1 = null // Compilation error
val s2: String? = null
if (s2 != null) {
print("String of length ${s2.length}")
}
val maybeLength: Int? = s2?.length
val length: Int = s2?.length ?: 0
8. Data Classes
// 69 lines in Kotlin vs 842 lines in Java
data class ArchiveData(
val orderId: Int,
val orgId: Int? = null,
val orderStatus: Int? = null,
val orderCreated: String,
val orderLineId: Int? = null,
val productId: Int? = null,
val productClass: Int? = null,
val adId: Int? = null,
val contractId: Int? = null,
val productPrice: Double? = null,
val orderLineCurrency: String? = null,
val paymentId: Int? = null
// 45 additional fields..
)
9. Data Classes - easy to manipulate
val order = createOrderTakeout().copy(
phone1 = "phone1",
phone2 = "phone2"
)
order.phone shouldEqual "phone1, phone2"
val order = createOrderTakeout().copy(
phone1 = null,
phone2 = null
)
order.phone.shouldBeNull()
10. More pros/cons in Kotlin
Extension functions
Coroutines
Simpler lambdas
Pattern Matching & Smart Casts No package visibility modifier
Elvis operator and .let() for nullables
Learning curve
Eager collections
Integration Java and JVM
11. Kotlin at Finn
Reise
(Most new code)
Search
(7 apps)
Billing
(5 apps)
Apps - Android
(All new code)
AdView
Scala + Haskell
Customer
(2 apps)
Classified Ad
(1 app)
12. Should you use Kotlin?
• Will not Java catch up and isn’t Java a safer bet long term?
• Start with small application that is not important
• https://github.schibsted.io/finn/kotlin-example-app