
Kotlin is the hero Android needs - kasiakrn
https://10clouds.com/blog/kotlin-android/
======
jrwiegand
It makes me sad that people are so upset by the recent hype Kotlin is getting.
Everyone has something that they get excited about. Kotlin is new and shiny
and has been around awhile but only on the fringe. Google brings it to the
spotlight and people are going to be interested. Maybe Kotlin gets big, maybe
not but there is no need to get angry about the news. It is big news. Android
is the most used smartphone OS in the world[1]. This is going to have an
impact somewhere.

1:
[https://en.wikipedia.org/wiki/Usage_share_of_operating_syste...](https://en.wikipedia.org/wiki/Usage_share_of_operating_systems#Worldwide_device_shipments)

~~~
jorgemf
I like kotlin and I am not angry about the news. I am angry because the people
is starting to notice it now because Google bla bla bla. It is a great
language, with or without Google, it is going to keep being a great language.

There were so much hype about swift, when kotlin was here and probably doing
better (no incompatibility issues between versions for example). Swift and
kotlin are the languages to look to the future. One or two years ago, and
today.

I wish the people would have more critic sense and asses the things by
themselves before a big company says anything. (Because kotlin was great
before Google said anything)

~~~
bitsoda
You're coming across as a Kotlin hipster. I would just be happy the language
is now on more people's radar. Maybe some folks had never even heard of the
language before this year's IO. Learning a new programming language and its
idioms isn't a trivial time investment for devs swamped with work, so waiting
until a heavy hitter like Google throws its weight behind it is quite a
pragmatic approach.

~~~
jorgemf
I am happy more people is aware of kotlin now, I am not happy the people
wasn't aware before. Even when you were pointing them to the goods of the
language. But still I trust more JetBrains than Google for programming
langues, only because is a company that create tools for programmers, they
have more experience.

~~~
fauigerzigerk
The suitability of a language for a particular project doesn't just depend on
language features.

Most new languages will fade away without ever getting enough traction to
survive. It's a real risk that is mitigated by corporate backing.

Many people may have been aware of Kotlin's strengths but found themselves
unable to justify its use for a mission critical task.

------
seanalltogether
The hero that android needs is a complete rewrite of Activities and Fragments
into something that makes sense in a stateful application

~~~
Nandi
Kotlin was not required. Android developers keep losing focus on what's more
important and what's less; with the dance of variations of MVP patterns,
RxJava, 10 ways to do the same shit. Now even Google has to focus on 2 things,
providing support for 2 languages. Java 9 is on the verge of being released
and we are just getting parts of Java 8. Yes, we do not need all features, but
what we actually need is FOCUS.

~~~
jondwillis
What would you like "us" to focus on? As for MVP variations and RxJava, those
are useful tools. MVP variations are often for organization and writing more
modular, testable code. RxJava and other Rx implementations are useful for
describing data flows and transformations while also making complicated
asynchronous problems more manageable.

~~~
Nandi
MVP & Rx are good, no doubt. But there are a crazy amount of Pundits preaching
different variations and thanks to the internet an early developer/beginner is
confused. I have spent several hours helping others rectify basic mistakes.
There should be some serious and well-documented approaches to achieve
something (a performant app in this case). Decay is also important. As
frameworks mature and android itself moves ahead, old documentation or answers
which no longer have relevance should be purged. Android documentation itself
boasts old sample codes, while the framework has deprecated some of them. The
problem which OEMs faced are being resolved now, but the reality is it will
take another year or two for it to come live. In 2013 Huawei had come up with
its own extension to segregate its own modification with vendor and base; very
sure that's not getting removed at least in the next 1 year.

------
eng_monkey
WTF? Some people are spending serious money on a PR campaign to promote Kotlin
this week!

~~~
StevePerkins
1\. Android is the largest mobile platform on the planet.

2\. It's been around for a decade now, but has only supported development with
Java and C++.

3\. The most recent version of Java supported comes from 2011. And full C++
support is only recent.

4\. Few people (if any) really like these options.

5\. This week Google announced that Kotlin is the next "official" language
with first-class support.

6\. A temporary wave of stories appear on HN.

Are you new here? I'm sure that next week it'll go back to the usual threads
about Rust or Haskell, or someone will start a retro fad around Algol-68 or
something.

~~~
IanDrake
You can write android apps in c# or JavaScript too.

I'm not sure if you consider them "supported" but they both have pretty
advanced tooling for the purpose.

~~~
StevePerkins
If you write a C# app with Xamarin and have problems, then it's Xamarin's
support problem. If you write a JavaScript app with Qt (I assume?), then it's
Qt's support problem.

Now, if you write an app with Kotlin, then it's _Google 's_ support problem. I
can see how that would change the game for a lot of shops.

~~~
AlphaSite
I'm not sure I trust google to support anything properly, I'm glad it's
Jetbrain's problem. Atleast their tooling isn't garbage.

~~~
m_fayer
It is much easier to squeeze support out of Xamarin than Google.

------
bauerd
Can someone compare their productivity with React Native or Xamarin to
"native" Java/Kotlin development? Having used RN, the whole state/data layer
can be shared across two platforms, and I guess the same is doable with C# and
Xamarin. I get that both require bridges when interfacing with ObjC/Java,
whereas Kotlin seems to have great (but only) Java interop.

~~~
m_fayer
I can only say I'm way more productive in Xamarin than I am in Android native
with Java, I do a fair bit of both. I'm excited about Kotlin and will
definitely give it a try, but Xamarin does still retain some advantages over
Kotlin, even though it seems to be a slightly more advanced language than C#:

Xamarin allows you to target iOS, MacOS, and Windows in addition to Android.
Though you have to rewrite the view layer for each platform. If your view
layer is in HTML, then you mostly have WORA.

Xamarin converts a lot of crufty weird Android API to a slightly more modern
form. So instead of int constants hanging off random classes all over the
place, you have proper enums.

Coroutines and async/await seem much more ready for primetime in C# than in
Kotlin.

Xamarin builds seem saner and faster than Android native.

There's some very advanced and battle-tested C# libraries that Xamarin opens
up that I think are unmatched in native Android land. For full-application
frameworks, ORMs, DI, databinding, and serialisation.

There's way more C# devs in the world than Kotlin devs.

Though I have to say that Xamarin has one big disadvantage - it adds another
layer of sometimes leaky abstraction, and a whole new source of framework bugs
to Android. So you spend a lot of time asking yourself "is this a Google bug,
or a Xamarin bug, or my bug?"

~~~
pjmlp
> Though I have to say that Xamarin has one big disadvantage - it adds another
> layer of sometimes leaky abstraction, and a whole new source of framework
> bugs to Android. So you spend a lot of time asking yourself "is this a
> Google bug, or a Xamarin bug, or my bug?"

This the main reason why while I dabble in all interesting technologies to get
a taste of what they bring into the table, production code is always written
100% with official SDK languages for the system being targeted.

------
dullgiulio
Someone in an earlier Kotlin discussion (there has been quite a few just
today) was praising how Kotlin solves the "1M$ mistake" having no null. He was
also complaining that sadly is day-to-day job involves Go.

Unline Kotlin, Go does support len() (.length in Kotlin) on nil:
[https://play.golang.org/p/koqYbIdltw](https://play.golang.org/p/koqYbIdltw)

In Kotlin, b.length can throw a NPE, only a b?.length won't (it will return
zero or null, I have not understood that).

Together with the var/val debacle, it seems like it is designed to be very
terse, which can lead to easier errors.

I don't think it solves the 1M$ mistake at all. And how could it, while
maintaining full compatiblity with Java?

~~~
Filligree
The only way b.length would compile, if b is a nullable array, is if it's
defined in a Java class. In which case Kotlin will _assume_ it's non-nullable
in the absence of nullability annotations. That is not perfectly ideal, but
it's not Kotlin's fault; they decided (rightly, I think) that the reduced
friction is worth the risk. And you can add annotations.

If b were defined in kotlin, as nullable, then b.length is a type error. You
can use b?.length, or you can add an explicit null check and depend on the
smart cast.

------
johnnycerberus
I am what they call a Dilbertish Java Developer and I really like what they've
done with Kotlin, wanted to jump ship to .NET ecosystem just because of C# but
now I changed my mind. Articles like this are focused on syntactic sugar and
kool-aid. What I really want to know is the following:

How different is idiomatic Kotlin in respect to Java?

How complex Kotlin Native will get? (I know that they want it for iOS, IoT,
games, data science but something like this will require some types of manual
memory mechanism, at least for gaming)

Will Kotlin Native work in Android NDK (calling it from JVM in general)?

Will Kotlin Native support WebAssembly?

~~~
vbezhenar
> How different is idiomatic Kotlin in respect to Java?

Not much, but there are differences. It's generally things that Java just
don't have.

> How complex Kotlin Native will get? (I know that they want it for iOS, IoT,
> games, data science but something like this will require some types of
> manual memory mechanism, at least for gaming) Will Kotlin Native work in
> Android NDK (calling it from JVM in general)?

I think it'll be native code with small stdlib which will compile to many
platforms. So generally if you can write something with C, you'll be able to
use Kotlin.

> Will Kotlin Native support WebAssembly?

I think so. Kotlin Native uses LLVM and LLVM can produce WebAssembly output.

------
moondowner
"Remember filtering lists with for loops? Thanks to the functional approach to
collections, we can also reduce all the complex, multiline instructions to
only one line of code."

Erm, same can be done in Java with the Java 8 stream API.

I like Kotlin and use it with Spring, but articles like this where programming
languages are not compared properly make me cringe.

~~~
StevePerkins
Even after 10,000 armchair lawyer discussions about the Google-Oracle lawsuit,
I feel like 99% of developers still do not grok that Android's "Java" isn't
really Java.

They wrote their own implementation of an earlier version, and at this point
will probably never update its API to fully match Java 8 or beyond. Android
devs who want advancements will have to add "shims", like retrolambda or
(quite frankly) Kotlin.

~~~
pjmlp
Aka language fork.

------
ericfrederich
> Remember POJOs? With the introduction of Kotlin’s data classes, we can say
> goodbye to generating the getters and setters for all object fields and
> writing implementations of toString(), hashCode() and equals() methods.
> Instead of 50+ LOC in Java, we can reduce that number to 1 (!) in Kotlin.

So this is like Python's attrs module

------
yeasayer
It's very sad that our industry is so hype driven.

Nothing really changed, you could write Android apps on Kotlin before, as well
as on any other JVM language. But now "Kotlin is the hero".

I suspect that Google's adoption of Kotlin is just politics: JetBrains
develops Android Studio for Google, so they pushed Kotlin as part of the deal.
Google could acknowledge Scala years ago, but didn't, because Scala authors
spend less time on bullshit politics and more time on actually improving the
language.

Also, I don't understand the point of Kotlin. Clojure, Groovy and Scala are
all very distinctive from each other and have their own niche. Kotlin is just
a subset of Scala. Same thing, but less features. I guess it's NIH principle
applied to JetBrains.

~~~
jbooth
Kotlin is a smart subset of Scala.

Scala did a lot of things that pushed mainstream programming forward, but it's
also crapped up with a lot of detritus, ideas that didn't work out, and ideas
that were always obviously bad.

~~~
jorgemf
> Kotlin is a smart subset of Scala

Yes, it is only the subset you need, nothing else. That is why is here to stay
and Scala not.

Making the things more complex doesn't mean making them better. Do one thing,
and do it right. Don't do a lot of things half good.

~~~
pkolaczk
Scala does all the features of Kotlin equally well, not half good.

Actually Kotlin inherited a few bad ideas from Scala as well - which Scala
already dropped like procedure syntax.

And some features like null handling or coroutines in Kotlin are implemented
as language features - special cases in the compiler, because the core of the
language lacks abstraction mechanisms. This is making the language _more
complex_ than Scala.

Scala: minimal and powerful language core, the rest is in libraries.

Dotty: make this core even smaller

Kotlin: take a powerful language like Scala, remove almost all of the unnique
abstraction features, leave only "better Java syntax" and then reimplement
missing features by special cases directly in the language instead of
libraries. Feels like VB of XXI century.

~~~
jorgemf
I have written Scala code and kotlin code, and it is much more legible the
kotlin code. When I tried also there were problems calling Scala code from
Java (I think there were problems with the type inference system that was
giving me non-sense errors). Scala adds like 500kb to an Android app, kotlin
only few kb. The compilation times are much faster with kotlin, the tooling
support is also better. It is easier to become more productive with kotlin
than with Scala.

> Scala already dropped like procedure syntax

Do you mean this?: [https://groups.google.com/forum/#!topic/scala-
internals/q1YX...](https://groups.google.com/forum/#!topic/scala-
internals/q1YX7NC1geM/discussion)

Kotlin does not do that.

> some features like null handling or coroutines in Kotlin are implemented as
> language features

null handling yes, and it is very well done. Coroutines so so, they added a
couple of keywords to the language and most of the implementation is in the
library. You can create your own coroutines:
[https://kotlinlang.org/docs/reference/coroutines.html](https://kotlinlang.org/docs/reference/coroutines.html)

Go do coroutines quite good and they have also implemented in the language,
why is it bad they use a couple of keywords for those special cases?

~~~
pkolaczk
> Scala adds like 500kb to an Android app

This is a lie. Please stop spreading these lies about Scala requiring a huge
runtime. Scala runtime adds about 30 kB, which is nothing in 2017.

> the tooling support is also better.

Both use the same IDE from Jetbrains and both are officially supported. Hard
to tell which one is really better, but Kotlin support has more issues in its
bug tracker, despite being less popular :P

> (nulls) it is very well done.

It is not. It makes the type system more complex, and you can't abstract over
optionals and other collection types. You also can't make your own flavor of
optional-kinds, like Either or Try that would behave similar to the builtin
nullability feature.

The biggest problem with builtin features is that you can't make your own
slightly different ones. You're at mercy of one company controlling the
language. With a smaller language + libraries, you can always fork a library
and do modifications.

------
akz92
Should someone that's starting to learn native android development switch to
Kotlin, or is it better to learn Java first?

~~~
w8rbt
I'd go with Java and the standard APIs at first. Kotlin looks very similar to
Java just less verbose (I have not used it) and they say that you can mix it
in with Java if you like.

~~~
SimbaOnSteroids
Kotlin uses Java Byte-Code and JetBrains has put in a lot of effort to make it
so that any Java you do write can be automatically translated into Kotlin in
their IDE's. Idk how well this works because I haven't tried it but apparently
it worked well enough for them to try and do it with JavaScript as well which
is still in Beta.

~~~
Filligree
It works well. The resulting code often won't compile without manual changes
on the Java side, but they're simple changes, and it does automate 90-95% of
it. I've never yet introduced bugs this way. It doesn't produce idiomatic
Kotlin, of course.

It's also a nice Rosetta stone while learning Kotlin.

------
teekert
So... I just started getting into writing an Android app. What would be the
advice... I installed Android studio last week, is that still a preferred IDE?

~~~
smnscu
Yep, don't know if you can change the channel in settings to get canary
updates, but either way I installed from here:
[https://developer.android.com/studio/preview/index.html](https://developer.android.com/studio/preview/index.html)

edit: I'm assuming you want, like me, to try Kotlin

~~~
edubarr
You don't actually need to use the 3.0 preview for kotlin development in
android. You can use the stable version and just follow the instructions
provided by jetbrains: [https://kotlinlang.org/docs/tutorials/kotlin-
android.html](https://kotlinlang.org/docs/tutorials/kotlin-android.html)

------
lghh
I just started trying to pick up Android development in the last few weeks.
I'm comfortable with Java from college, but don't really keep up with it or
the ecosystem. Should I consider Kotlin for learning the platform with, or are
the docs and learning resources Google provides not up to speed yet?

Note: I'd eventually just use Kotlin anyways cause I don't care all that much
for Java.

~~~
Filligree
It's easy to use Java libraries from Kotlin, to the point that there's nearly
a 1:1 syntactic mapping. So in my opinion, yes, you should be able to use
Kotlin from the start.

That said, I've never written an Android app. There may be issues with that
particular platform.

------
bfrog
Its not a hero and android doesn't need it. Android is a near monopoly, they
could tell us to start programming in Ada and we'd all have to follow along
whether we wanted to or not.

Java is baggage ridden. I wonder if Java would've been the language of choice
had Rust or Go existed when it was started.

------
megamindbrian
I don't see how this is at all true. Android store is unregulated and allows
anyone to submit a crApp. This language looks stupid and it's no different
than a dozen other languages in principle. Why not port Swift to Android so we
can truly write once and run on two places?

~~~
swsieber
Because Swift doesn't interoperate with Java, ergo removing any path forward
for a gradual migration. And if it did, then it'd fragment the Swift
ecosystem.

------
dreamcompiler
What about Clojure? If Kotlin works for Android, shouldn't Clojure by now?

~~~
ledgerdev
Clojure is unfortunately implemented in such a way that makes it extremely
slow to load/start. It's really only suitable for heavy duty long running
servers where you don't care about startup time or resource usage, the exact
opposite of what android apps need. It's sort of sad to see such an amazing
language packaged up in a J2EE'ish manner.

------
scarface74
I had mixed feelings about Kotlin when I first heard about it. Usually I
wouldn't think twice about a language developed and championed by a small
company. But the "small company" being JetBrains, I had a feeling it would be
well thought out with a good IDE. It doesn't seem like I'll be disappointed.
I've avoided Android development because I dislike both Java and Eclipse. Both
of those problems seem to be solved. Now of only the emulator was better and
building GUIs....

------
leshow
The Kotlin interest strikes me as funny, it feels like Java programmers are
just realising what the rest of us have been using for years is pretty nice.

------
had2makeanacct
Is it easy to learn for someone who doesn't know any programming languages
beforehand? Like I only know a bit of JavaScript

~~~
e12e
The strong point of kotlin is definitely that it's "java pseudocode" \- it's
what you'd have to write on a whiteboard to leave no questions about what was
elided. Like data classes - in kotlin you write the attributes, but get
setters and getters, so you could to validation on change or whatever you
might need steers for beyond beans.

Given that; it's a pretty simple language - a lot like python or ruby, but
with a touch more of syntax beurocracy.

If you only have _some_ javascript, it would probably be best to learn it from
a proper kotlin book - there's a few out/coming out - but I've not read them.

But if anyone took a typical "java as a first programming language"-book and
shifted it to idiomatic kotlin, such a book would probably be a decent first
programming book.

Note that I do agree somewhat with the comments about kotlin being lipstick on
java's broken and strange single-inheritance oo, which leans more on Simula
than Smalltalk. But I think the result is rather pretty. Maybe just because it
manages to get rid of so much cruft from java ("Doctor it hurts when I do
this." \- "Then stop doing that.").

~~~
had2makeanacct
Okay thanks, maybe I'll go into it through Java.

~~~
e12e
To be clear: I believe kotlin is a much better language to start with than
java (but then, java is a pretty awful language inmho). But I've yet to see or
read/hear about any books for teaching programming through kotlin as a ~first
programming language (while there are many for python, ruby, java etc - or
even lisp/scheme).

I would probably rate kotlin as a better starting language than javascript,
for that matter.

~~~
had2makeanacct
Wow that's a big one then, I wasn't a Computer Science student but I like
tech. Tried to learn Java a couple years ago and gave up, decided to go with
HTML/CSS on Codeacademy as baby steps and did Javascript from there. If Kotlin
is easier than that I'll definitely try to learn it ASAP I'm really
interested.

------
dafrankenstein2

        Lambdas
        Data classes
        Function literals & inline functions
        Extension functions
        Null safety
        Smart casts
        String templates
        Properties
        Primary constructors
        Class delegation
        Type inference
        Singletons
        Declaration-site variance
        Range expressions

------
betimsl
Kotlin examples on the site are not much different from Java ones. They're
almost identical in length. Why bother to use it and add one more step for
translation to a compiler chain that is already very slow.

Same with Scala. I once ported a Scala program to Java one and ended up with
much shorter and concise code.

~~~
krallja
> Why bother to use it and add one more step for translation to a compiler
> chain that is already very slow.

I think you have a misconception about how Kotlin and Scala are compiled. Java
source code is not generated by either of these compilers -- they both compile
directly to .class files, just like javac does. There is no extra step, just a
different step.

~~~
swsieber
But, from what I know, Scala is compilation is really, really slow. So if
you're only familiar with Scala and not Kotlin, you may get the wrong idea.

------
limeblack
Does anyone know of something like hyperpolygot.org for Kotlin? I guess my
main question is can anonymous functions be nested with out requiring final in
Kotlin? Java requires final either implicitly or explicitly which makes
anonymous functions rather uslesss.

------
velebak
I've been watching this for a bit - it is my understanding that large parts of
IntelliJ itself are written in Kotlin.

I, for one, am very interested in how I can use it to speed my JVM-based
development.

I'm also interested in doing front end dev with it as well.

------
vitoralmeida
Genuine question: what is wrong with Java from a pragmatic point of view?

~~~
kentosi
One major issue is that Android only supports java 6. All the nice things java
8 brings aren't available. With Kotlin officially supported in Android, you
can finally have nice things.

------
rocky1138
Title is hype. IMO the hero Android needs is root access to be accessible
easily out of the box. Buying closed phones is a fool's game.

Sincerely, a developer.

------
cdevs
What's with the kotlin hacker news spam this week? Isn't one article enough?

~~~
DiThi
During Google I/O it has been announced as a officially supported language in
Android to the same level as Java, so all documentation, tooling, etc, will
have a Kotlin version. Therefore, everybody wants to know more about this
language.

~~~
githubber123
Thats right, forgot google io stuff is going on, makes sense. After a apple
keynote we see ipad and swift flooding to the top.

------
taneq
Did someone spend some cash on 'promote this link' for Kotlin today? It seems
like we've had a flood of Kotlin links.

I mean, the first one I saw was Steve Yegge's so that lends a bunch of
credibility but still, this is more than Baader-Meinhoff.

~~~
mike_hearn
I think you're just underestimating the huge number of Java programmers in the
world, and what this announcement means for them, that's all.

HN is usually flooded with stories like "Show HN: I wrote a config parser in
Rust" or "Show HN: a web server that serves JSON in Go", which are irrelevant
to 90% of working programmers. We just get blind to it. There's no money at
work there, just the enthusiasm of the users ... along with a dire need to
spark enthusiasm in others given that Rust and Go hardly interop with anything
except C.

Kotlin's getting a lot of attention right now, but it'll die down because
Kotlin users don't need to win converts to their ecosystem. You won't be
seeing the next two years of HN front pages be filled with "My experience of
converting a microservice to Kotlin" type stories, because Kotlin users can
just use all the Java and JVM ecosystem support already, so there's no need to
win people over. Getting more Kotlin users in the world doesn't make a huge
difference to your own experience.

------
la_oveja
The hug of death

~~~
chrossh
It's back!

------
skdotdan
Did anyone said Kotlin?

------
dreta
It's just Java with a few Swift features. The only thing Kotlin does is help
you to be more efficient at writing terrible OO code.

This is even less of a reason to to be excited than when C++ came out, and
solved none of the issues C had, just introduced a weak inheritance system,
and search-and-replace level of meta-programming.

