Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Intro to Kotlin
15.10.2015@Infinum Dino Sulić & Tomislav Homan
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Java on Android - the bad parts
● Java 7 was out 2011. - partial support 2013.
● Java 8 was out 2014. - no support announc...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Alternatives to Java
● Xtend - Nice try, but very hard to work with in practice because
of IDE support
● Scala - We are en...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Advantages of Kotlin (I)
● Modern statically typed, object oriented language that borrows
many ideas from functional langu...
Advantages of Kotlin (II)
● The team behind it is JetBrains, creators of IntelliJ which is
Android Studio based on. Also h...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
(Possible) disadvantages (I)
● Code generation - After a long struggle works with, for now,
limited support - Dagger 2 wor...
(Possible) disadvantages (II)
● Java could break when using immutable collections returned
from Kotlin code
● New language...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Features
Selection of features compared to
Java
First thing that one will notice is function declaration includes
keyword fun
Functions (I)
Parameter types are defined in Scala (Or Swift) way
Functions (II)
Default parameters come in handy
Functions (III)
Named parameters as a good substitution for builders
Functions (IV)
Functions are first-class Kotlin citizens
Functions (V)
Lambdas on Android? Not using Java
Functions (VI)
Lambdas on Android? Kotlin has them
Functions (VII)
Nice Retrofit example - cumbersome using Java
Functions (VIII)
Nice Retrofit example - pretty decent using Kotlin
Functions (IX)
Utility methods vs. extension functions
Functions (X)
Kotlin inferes types
Types (I)
It is difficult to write “final”. Kotlin makes it easier with val keyword
Types (II)
Java fields become Kotlin property. No need for getter / setters
unless you want to override them
Properties (I)
If you have the need for some validation…
Properties (II)
...you can still override accessors and access backing field
Properties (III)
Nothing to say here
Null safety (I)
You have to explicitly use nullable type if you want to allow nulls
Null safety (II)
If you use nulls though, safe calls, Elvis and smart casts are here to
help
Null safety (III)
Explicit vs. smart casts
Casting
In order to make this business logic right….
Data classes (I)
You have to do some work
Data classes (II)
In order to make this business logic right….
Data classes (III)
...you use data modifier
Data classes (IV)
Typical data repository
Collections (I)
Some business logic
Collections (II)
And lots of error prone work
Collections (III)
Same typical repository
Collections (IV)
Some business logic. Collections are really immutable
Collections (V)
But much less work
Collections (VI)
Just one more example...
Various (I)
...how Kotlin gets some things better
Various (II)
Out of scope
● Generics - variance, covariance, contravariance
● Annotations
● Reflection
● Operator overloading
● Type-sa...
Content
● Java on Android - the bad parts
● Alternatives to Java
● Advantages of Kotlin
● (Possible) disadvantages
● Featu...
Migration to Koltin
● https://kotlinlang.org/docs/tutorials/kotlin-android.html
● Use convert code option - but check thor...
Intro to kotlin
Upcoming SlideShare
Loading in …5
×

Intro to kotlin

2,369 views

Published on

If you still haven't heard of it, there is a new star in JVM sky - Kotlin. This short presentation will serve as intro for those who wan't to hear what's all the fuss about and dive deeper into this new alternative to Java

Published in: Software
  • Be the first to comment

Intro to kotlin

  1. 1. Intro to Kotlin 15.10.2015@Infinum Dino Sulić & Tomislav Homan
  2. 2. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  3. 3. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  4. 4. 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
  5. 5. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  6. 6. 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
  7. 7. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  8. 8. 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
  9. 9. 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
  10. 10. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  11. 11. (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
  12. 12. (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
  13. 13. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  14. 14. Features Selection of features compared to Java
  15. 15. First thing that one will notice is function declaration includes keyword fun Functions (I)
  16. 16. Parameter types are defined in Scala (Or Swift) way Functions (II)
  17. 17. Default parameters come in handy Functions (III)
  18. 18. Named parameters as a good substitution for builders Functions (IV)
  19. 19. Functions are first-class Kotlin citizens Functions (V)
  20. 20. Lambdas on Android? Not using Java Functions (VI)
  21. 21. Lambdas on Android? Kotlin has them Functions (VII)
  22. 22. Nice Retrofit example - cumbersome using Java Functions (VIII)
  23. 23. Nice Retrofit example - pretty decent using Kotlin Functions (IX)
  24. 24. Utility methods vs. extension functions Functions (X)
  25. 25. Kotlin inferes types Types (I)
  26. 26. It is difficult to write “final”. Kotlin makes it easier with val keyword Types (II)
  27. 27. Java fields become Kotlin property. No need for getter / setters unless you want to override them Properties (I)
  28. 28. If you have the need for some validation… Properties (II)
  29. 29. ...you can still override accessors and access backing field Properties (III)
  30. 30. Nothing to say here Null safety (I)
  31. 31. You have to explicitly use nullable type if you want to allow nulls Null safety (II)
  32. 32. If you use nulls though, safe calls, Elvis and smart casts are here to help Null safety (III)
  33. 33. Explicit vs. smart casts Casting
  34. 34. In order to make this business logic right…. Data classes (I)
  35. 35. You have to do some work Data classes (II)
  36. 36. In order to make this business logic right…. Data classes (III)
  37. 37. ...you use data modifier Data classes (IV)
  38. 38. Typical data repository Collections (I)
  39. 39. Some business logic Collections (II)
  40. 40. And lots of error prone work Collections (III)
  41. 41. Same typical repository Collections (IV)
  42. 42. Some business logic. Collections are really immutable Collections (V)
  43. 43. But much less work Collections (VI)
  44. 44. Just one more example... Various (I)
  45. 45. ...how Kotlin gets some things better Various (II)
  46. 46. 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/
  47. 47. Content ● Java on Android - the bad parts ● Alternatives to Java ● Advantages of Kotlin ● (Possible) disadvantages ● Features ● … ● Migration to Kotlin
  48. 48. 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

×