12 Replies Last post: Jun 14, 2012 1:12 PM by James Strachan  
Otto von Wachter Newbie 74 posts since
Jan 15, 2004
Currently Being Moderated

Jun 12, 2012 10:37 PM

Any tips for a Kotlin presentation?... and thinking in Kotlin

I'm giving a short presentation on Kotlin tomorrow at my company, and this got me thinking about what to talk about, mainly which advantages/features of Kotlin might be useful/appealing to our development team.  

 

So I've been thinking about is what are the greatest advantages of using Kotlin, and I think the biggest is the functional paradigms.  But as a Java developer, I don't have a lot of experience in functional programming.  I started reading the book "Functional Programming in Java", and this was somewhat helpful.  Does anyone have any other good resources for learning good functional programming paradigms?  Along the way I found this pretty good article by Bruce Eckel, the author of Thinking in Java: http://www.artima.com/weblogs/viewpost.jsp?thread=328540  It is about Scala, but I guess it can largely apply to Kotlin as well.  It would be great if someone wrote an article like this that talks about Kotlin.

 

Anyway, here is the outline of the topics I was planning to talk about for this presentation:

 

Kotlin features

- functional programming (first class functions, delegation, function literals, higher-oder functions, infix functions/LINQ-like queries)

- extension functions means you can add useful methods to classes (like C#, and categories in Objective-C)

- null-safety (no NPEs), properties, operator overloading, local type inference

- inline functions: performant control structures

- build infrastructure (modules) as part of the language

Kotlin advantages

- the upshot of all the features above: better, more readable code

- plays well with Java.  Seamless integration with Java means that you can use it where it's useful/needed, but keep java code you already wrote, and refactor code slowly instead of having to throw out all your java code at once.

- first-class IDE developed by JetBrains

 

Here's what I was NOT planning to talk about... Builders, declaration/use-site variance, reified generics.  I could talk about them, but I don't think the developerment team would care that much about it and honestly I don't understand these features very well myself... although they are definitely kool features

 

If anyone has any ideas, tips for a presentation, please reply.  Also, does anyone have any resources I can use for a presentation? (good code examples, a slide deck, etc.) that could save me some time for this.  Thanks!

James Strachan Novice 174 posts since
Apr 29, 2003
Currently Being Moderated
Jun 12, 2012 11:00 PM in response to: Otto von Wachter
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

That all sounds good to me. Some other benefits of Kotlin are:

  • compiles both to JVM bytecode and to JavaScript (admittedly the latter needs some work). e.g. http://kotlin-demo.jetbrains.com/
  • simple & very easy to learn and read (e.g. compared to Java or Scala)
  • much fast compiler than scala and small runtime footprint compared to scala & groovy
  • eventually a much more stable binary story than Scala
James Strachan Novice 174 posts since
Apr 29, 2003
Currently Being Moderated
Jun 13, 2012 9:56 AM in response to: Otto von Wachter
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

I guess you could leave out the binary stability of scala issue; its only really applicable if you're talking to a scala crowd. But with scala whenever the compiler changes you pretty much have to have all your scala based dependent libraries rebuilt with the same version of the compiler & you have to upgrade all scala dependencies at the same time; so there's this big dependency-re-release dance which I don't really see scaling in the enterprise - though its fine for greenfield startup type environments. Typically folks in scala use sbt so that they re-release each release of a jar compiled against lots of different scala compiler versions. From Kotiln 1.0 this shouldn't be an issue; mostly as Kotlin avoids traits with fields & reuses the JDK's collections.

James Strachan Novice 174 posts since
Apr 29, 2003
Currently Being Moderated
Jun 14, 2012 1:12 PM in response to: James Strachan
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

Another nice benefit of Kotiln is nicer API documentation which is searchable (try typing "find" into the Search box top right for example) generated using wiki notation (markdown the default on github) and reusing markdown ReadMe.md files in package source directories  so that things look nice in github when looking at the source or in the API documentation when looking at a package description.

 

Also the API documentation allows inclusion of blocks of code from test cases to help illustrate methods via the @includeFunction macro; so its easy to create testable documentation which is refactoring safe.

 

Finally the API documentation includes a source link both to the implementation of a method and its test case example code by default. For example if you hover over the Iterable<T>.filter() method description, notice the source links on the right which take you straight to the relevant lines of code in the github source code or test case.

Cedric Beust Novice 122 posts since
Mar 1, 2012
Currently Being Moderated
Jun 13, 2012 12:44 AM in response to: Otto von Wachter
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

I wouldn't push the functional aspect too much (if at all) because of all the baggage that comes with it and also because Kotlin doesn't go as far into functional programming as a few other languages.

 

I think the main value of Kotlin is that it's an incremental improvement over Java. The fact that some of these improvements are rooted in functional programming probably doesn't need to be mentioned if you are presenting to a crowd that is not already sold on the need for a better language.

 

Start by showing some paint points in Java and then show the equivalent Kotlin code, this should be enough to gain some attention.

Dody Gunawinata Novice 160 posts since
Apr 4, 2012
Currently Being Moderated
Jun 13, 2012 1:51 AM in response to: Otto von Wachter
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin
  • Less code
  • Traits
  • Pattern Matching

 

I am building 101 samples for Kotlin as part of my learning here https://github.com/dodyg/Kotlin101. You might find them useful.

Dody Gunawinata Novice 160 posts since
Apr 4, 2012
Currently Being Moderated
Jun 13, 2012 4:41 AM in response to: Otto von Wachter
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

It's a neat feature that is useful in working with tuple. I have no idea about the big idea behind it. I quote this sample from http://confluence.jetbrains.net/display/Kotlin/Control+structures

 


when (tuple) { 
  is #(1, 2) -> ... 
  is #(val a, 3) -> print(a) // binding a to the first element of the tuple 
  !is #(*, 1100) -> ... 
  else -> ... 
}


 

Unfortunately the complex pattern like above is not working yet with the current M2.

 

Another thing that I love is the when shortcut

 

fun main (args : Array<String>){
    var x = 101
    val greater = { (x : Int ) -> x > 100 }

    when {
        x in 1..50 -> print("In range")
        greater(x) -> print("Great")
        else -> print("Outside range")
    }
}

 

Cedric Beust Novice 122 posts since
Mar 1, 2012
Currently Being Moderated
Jun 13, 2012 5:50 AM in response to: Dody Gunawinata
Re: Any tips for a Kotlin presentation?... and thinking in Kotlin

The ideas behind this concept are "algebraic data types" and "pattern matching".

 

I believe the Kotlin team has plans to extend this in future milestones with... I'm not sure the term they used, "value classes"?

More Like This

  • Retrieving data ...