Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Kotlin

Intro to Kotlin

Introduction to the Kotlin programming language for Java developers

tomislavhoman

October 08, 2015
Tweet

More Decks by tomislavhoman

Other Decks in Programming

Transcript

  1. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  2. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  3. Java on Android - the bad parts • Java 7

    was out 2011. - partial support 2013. • Java 8 was out 2014. - no support announced in the near future • Null references • Covariant arrays • Raw types • SAM types • Checked exceptions
  4. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  5. Alternatives to Java • Xtend - Nice try, but very

    hard to work with in practice because of IDE support • Scala - We are engineers with deadlines, not scientists. Also 80k methods • Groovy - Very nice, but not type safe and adds over 30k methods. IMHO best alternative - to our alternative :) • Closure, etc, etc… • Kotlin
  6. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  7. Advantages of Kotlin (I) • Modern statically typed, object oriented

    language that borrows many ideas from functional languages • Fast learning curve - inspired by Scala and C#. Scaled down Scala :) • Meant to be used for building large software systems • Engineered to be highly interoperable with Java - you can use existing code base w/o (many) problems
  8. Advantages of Kotlin (II) • The team behind it is

    JetBrains, creators of IntelliJ which is Android Studio based on. Also has some contributions from James Strachan - creator of Groovy • Significantly more concise and readable than Java, which means it’s easier to maintain • Lightweight - Kotlin stdlib has 8k methods • If it means something to someone - it also compiles to Javascript
  9. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  10. (Possible) disadvantages (I) • Code generation - After a long

    struggle works with, for now, limited support - Dagger 2 works • Mocking and testing - managed to run AndroidTestCase with Mockito, but no serious testing done • IDE was still bit unstable few months ago, but it seems fine now and it can only get better. But still be patient for now
  11. (Possible) disadvantages (II) • Java could break when using immutable

    collections returned from Kotlin code • New language that still evolves - teams need to establish code conventions - still no "Effective Kotlin" :) • Interoperability with new Jack and Jill compiler - should be all right, but we have to monitor the situation
  12. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  13. Java fields become Kotlin property. No need for getter /

    setters unless you want to override them Properties (I)
  14. If you use nulls though, safe calls, Elvis and smart

    casts are here to help Null safety (III)
  15. Out of scope • Generics - variance, covariance, contravariance •

    Annotations • Reflection • Operator overloading • Type-safe builders • Dynamic types • Java interop • …and lot more • http://kotlinlang.org/docs/reference/
  16. Content • Java on Android - the bad parts •

    Alternatives to Java • Advantages of Kotlin • (Possible) disadvantages • Features • … • Migration to Kotlin
  17. Migration to Koltin • https://kotlinlang.org/docs/tutorials/kotlin-android.html • Use convert code option

    - but check thoroughly afterwards • Use clean code option after upgrading Kotlin version • KotlinFrontEndException • > sudo find . -name ".DS_Store" -depth -exec rm {} \; • This list was much longer few months ago