Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Why did you choose Kotlin? #2

Open
Rainer-Lang opened this issue Jul 4, 2016 · 2 comments
Open

Why did you choose Kotlin? #2

Rainer-Lang opened this issue Jul 4, 2016 · 2 comments

Comments

@Rainer-Lang
Copy link

No description provided.

@AAverin
Copy link
Contributor

AAverin commented Jul 4, 2016

There are many reasons, that start making sense when you are already into Kotlin.
But while you're still in Java, there is only one - Kotlin is easier to write and easier to read, while it has almost no overhead.

There are many features in Kotlin that beat Java7 to it's knees. Java has to be backwards compatible, so it can't afford any significant changes.
Kotlin has amazing syntax-sugar and features, like:

  • no more semi-colons
  • default implementation on interfaces - no more class that implements some interface so you wouldn't have to override all methods
  • default values for function parameters - more concise function signatures, and more readable too
  • lambdas as first-class citizens of the language and not just class-based implementations and workarounds - cleaner and easier to read code, you don't need retrolambda anymore
  • operators on collections - map, filter, reduce and others
  • string templates - no more boilerplate with 'format'
  • optionals - forget about null pointer exceptions (almost)
  • data-classes - you don't need AutoValue any more
  • extension functions - makes code so much cleaner in many cases, like, forget those Utility classes and 'MyResUtils.pxToDp' - just put it on Resources directly

And you get all this and many more for free, because you can still keep using your favorite Java libraries - Java code can be called from Kotlin and vice-versa.

Now, that list, for sure, will be shorter when Java8 will be available for everybody, but that would still be a while.

I'm not sure how much Kotlin makes sense for the backend development - there are not much constraints there - but for Android I think it's a clear winner.

There are some downsides that can affect your decision though.

  • Kotlin is still relatively young, so there can be some rough edges here and there. They were mostly polished during long pre-release phase, but some issues are still present. Although, guys from Jetbrains are very helpful in their Slack-channel, and in general issues are noticed and addressed quickly. Not like when you make and issue on android google bugtracker, which rarely gets any attention.
  • Kotlin has to play catch-up games with Android Gradle Plugin and all those bells and whistles guys at Google try to add to latest Android Studio. That results in a bit outdated feature compatability. Like, you wouldn't use latest gradle plugin - project just will not compile with kotlin, especially if you are also using latest databinding. And it took some time to add support for Instant Run, but with Kotlin 1.0.2-1 (maybe 1.0.3 in some cases) - incremental builds and Instant Run also work fine.
  • Some bugs (like NonExistentClass or some random compilation issues) will be really difficult to workaround and fix, and that will really piss you off and drive you nuts some times. Issues are already in Jetbrains tracker and are being worked on
  • Refactoring in IntelliJ sometimes gives weird results. Also, there are still not so many static analysis tools made specifically for Kotlin. Refactoring bugs are already in tracker and are being worked on, and static analysis tools are not yet a high-priority, although promised to be added some time in the future
  • kapt (Kotlin Annotations Processor) is still some times buggy. Some of the most critical bugs still present come out of it. But, there is already initiative to have a new annotation processing in Kotlin 1.0.4 that, hopefully, will solve all of the problems left.

In any case, I think Kotlin is improving very quickly and most of the critical issues are already covered.

I would really love to have some kind of official green-light from Google to embrace Kotlin for Android development. According to Google guys - they don't mind people using Kotlin and they, as developers, don't really have to do much to make sure it's supported - it just works. But so far there was no indication that Kotlin would become and official language for Android.

Hope that answers the question in full =)

@Rainer-Lang
Copy link
Author

Oh WOW. :) 👍
A very comprehensive answer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants