
Learn Kotlin in Y Minutes - jakub_g
https://learnxinyminutes.com/docs/kotlin/
======
coldpizza
> Declaring values is done using either "var" or "val". "val" declarations
> cannot be reassigned, whereas "vars" can.

I wonder why they decided on these very mistakable names. Why not
const/constant/cons/whatever else just as long it's distinguishable from each
other?

~~~
namelezz
var = variable (can vary/change)

val = value (constant)

What can be mistaken?

~~~
melling
I don't find it to be confusing but you'd get more autocomplete help if let
was used for constants.

l => let

v => var

~~~
dajohnson89
Very good point. Fortunately, it's only one keystroke saved.

~~~
melling
One keystroke, not two? I type l<tab> in Xcode then I'm typing in the variable
name. You'll have to arrow down if it's the wrong one then hit return.

You can argue that it's really not much extra work but it all adds up.
Especially when you try to code on a tablet, which I find myself doing
occasionally.

------
jorgemf
I like kotlin a lot, but suddenly there are a lot of articles in the front
page about it. Kotlin isn't more cool because Google announced yesterday it is
going to use it in Android. Kotlin is the same good language it was 2 days
ago! (rant over)

If you want to learn kotlin go to the official docs and tutorial, they are as
good as the language:

[http://kotlinlang.org/docs/reference/](http://kotlinlang.org/docs/reference/)

And you don't need to install anything as you can try it in the browser:

[https://try.kotlinlang.org](https://try.kotlinlang.org)

~~~
prlambert
The language itself isn't 'more cool' or better, but the risk profile of
adopting it has dropped dramatically. That makes it much more interesting.

~~~
jorgemf
There weren't any risk before apart form the kotlin plugin not working with
beta versions of the gradle build plugin. Using kotlin in Android is like
using a library, and you don't have official support from Google for all
popular libraries used in Android.

~~~
ajmurmann
The risk was that you might end up with a code base that you cannot find
developers that will work on it/maintain it in the future. The Android support
should pretty much guarantee that there will be enough developers familiar
with it in the future.

~~~
jorgemf
If you are an Android developer you should be aware of kotlin long time and
and also tried and use it. Good Android developer knew kotlin before, now you
will face more noise to find them.

It is like hiring something who doesn't know the most used libraries in
Android. And the risk is exactly the same. The language is not difficult to
learn, not much more than a mid-complex library.

~~~
lghh
But Kotlin was farrrrrrrrrr from a "most used library". The risk of an
unsupported language being used is much, much greater than using an
unsupported library. Libraries are non-trivial to remove from your code, but
should not be tied to your code to the point that you will be required to
completely rewrite your application like you would if you ran into issues with
the language it's written in.

~~~
jorgemf
Say so to the people who is using RxJava or similar, whether they need to
rewrite everything or not. In every program you need to take architectural
decisions that affect how everything is build and a change on them could mean
to rewrite everything. It can be a library or the programming language.

JetBrains was supporting kotlin for Android, the same people that build
IntelliJ idea (the base of Android Studio). But who is supporting RxJava?
Imagine that the react community wants to make a move that will harm Android
devs, so they change all the Rx*, including RxJava.

Using kotlin wasn't a risk. Google said it will make it first class citizen,
but do you really trust Google in the long term? They close products very
quickly. I feel safer knowing that JetBrains is behind kotlin and not Google.

------
shubb
In terms of why we'd want to, there is this note here:
[https://kotlinlang.org/docs/reference/comparison-to-
java.htm...](https://kotlinlang.org/docs/reference/comparison-to-java.html)

Other factors to consider are tools support, how often interoprability with
java libraries causes problems. Would be nice to hear from someone who has
used it a bit about what the state of these is?

~~~
mintplant
To me the most promising aspect seems to be async-await on Android. It'd
eliminate _so much_ frustration in developing for that platform.

In general, after bouncing between various desktop, mobile, and web-based
technologies, I've come to the conclusion that any binding/event-based GUI
system _needs_ some sort of async-await or futures support to be truly
workable. Otherwise, performing background tasks without locking up the UI
involves way too much boilerplate and tends to blow up the architectural
complexity of the application.

~~~
stevenwoo
What do you think of EventBus on Android versus what you ended up using?
[https://github.com/greenrobot/EventBus](https://github.com/greenrobot/EventBus)
Just looking to learn new things.

------
notamy
Honestly I could never really get into Kotlin. I like the features of the
language - and would love to have many of them in plain ol' Java - but the
syntax just feels _wrong_ to me and I've not been able to get over it.

~~~
shallot_router
I find it a huge improvement over Java, but I wish it would have more syntax
sugar for lists/arrays/maps like Swift and dynamic languages do.

The mix of "hip" programming language constructs with unchanged Java verbosity
feels weird to me. But if I were making an Android app, I'd definitely try to
do it with Kotlin first.

~~~
WaxProlix
What kind of sugar are you looking for? I'd like to have first-class
comprehensions in any language I use, but having decent map/filter/reduce|fold
implementations is good enough for the most part.

(1..100).map({ it + 10 })

Doesn't seem so bad.

~~~
shallot_router
Mutable hashmap/associative array/whatever literals like:

    
    
        var map = {"a": 6, "b": 12}
    

[Whatever list type is most common/idiomatic in Kotlin] literals like:

    
    
        var list = [1, 2, 3]
    

etc.

Plus list/map comprehensions like Python or Haskell, as you mentioned.

Not a big deal or anything. It's only a little bit of extra typing. And the
syntax sugar they do add is definitely a massive step-up over Java.

I know it'd be hard to add the map literal syntax since it would clash with
Java's normal array literal syntax. And I also realize that Java has a wide
variety of container types for a reason, and Kotlin wants to be a subset of
and not replacement for Java, so doing this may not make a lot of sense.

I guess on reflection, my complaints aren't really valid given that context.
I've just had it ingrained in me to use special characters for basic container
types, since Python and JavaScript were my first languages for many years.

~~~
itp
While somewhat longer, you do have

    
    
        var map = hashMapOf("a" to 6, "b" to 12)
        var list = listOf(1, 2, 3)
    

This is still not Java-level verbosity.

~~~
shallot_router
I like that a lot, but the `to` syntax bugs me. Why not a colon, or Scala's
`->`?

~~~
ssijak
You type "->" faster and easier then "to"?

~~~
shallot_router
No, but it's visually clearer to me at a glance. It feels weird using letters,
let alone full English words, to describe a mapping or anything else that I
think a symbol is more suited for.

To me it would feel like assigning a variable with:

    
    
       a equals 6
       n equals "A"
    

Just feels icky, somehow.

Again, that wouldn't dissuade me from using the language whatsoever. It's only
a minor irritation.

------
westoncb
Is anybody here using Kotlin for back-end work? It seems like I generally hear
Kotlin come up in connection with Android, and less for writing server code,
though that's where I'd potentially like to use it.

~~~
vbezhenar
I've used Kotlin for standalone Java programs, it's great. According to
Jetbrains, it's roughly 50%:50% between Android guys and Java guys. I guess,
after yesterday announce it'll shift to Android.

For example Spring announced that Kotlin will be first class citizen with next
major release. So things are definitely bright on the server side.

------
subsidd
Kotlin's taken over HN.

~~~
softawre
Deservedly so. It is a great language, and it's backed by the ultra-power JVM.
You can use a hipster language with great features and still use JodaTime and
maven and all the enterprise stuff that just works.

~~~
betatest
What exactly make it a great language? What are the advantages compared to
Java? I search for it but couldn't find any simple answer to that question.
The fact that things are shorter to declare doesn't make it better. It makes
it less readable.

~~~
torinmr
I haven't used Kotlin, but glancing over their comparison page the one that
jumped out to me was that it (almost) eliminates the possibility of null
pointer exceptions: [https://kotlinlang.org/docs/reference/null-
safety.html](https://kotlinlang.org/docs/reference/null-safety.html)

~~~
tathougies
This is like an entry-level expectation for a modern language. Hardly
something to write home about in this day and age.

~~~
fixermark
It is when you bring it first-party to a platform the size of Java.

The userbase of Objective-C was much smaller before OSX brought Cocoa to the
Mac ecosystem.

------
Lerc
I like this

    
    
        val z = (1..9).map {it * 3}
                      .filter {it < 20}
                      .groupBy {it % 2 == 0}
                      .mapKeys {if (it.key) "even" else "odd"}
    

I'd like it more if it said it performed the functions in parallel. If it does
this Automagically I'm sold. If it doesn't, is there an easy to use form that
does do batch operations like map in parallel?

~~~
fineline
I guess they're just showing off mapKeys, but couldn't that line be eliminated
with:

    
    
      .groupBy {if (it % 2 == 0) "even" else "odd"}

------
eranation
Been watching Kotlin for a long time. Usually it pops out when I talk about
how great Scala is, and I get Kotlin as "what Scala should have been". I have
been avoiding using it at work instead of Java/Scala just because Scala had
more "buy in" and it was easier to convince people to try it. Now with the new
Google/Android (and HN) love, this is the perfect time to give it another try.

------
leshow
Does Kotlin have algebraic types? Possibly via sealed traits or the like,
similar to Scala?

~~~
dcow
Kotlin has sealed classes. It also has built in generic Pair and Triple
containers. But no it doesn't really have algebraic types as you see in
Haskell. For example, you can't build a linked list by `cons`ing Ints and
Strings and then take the dot product with another Int-String list. It still
relies on generics in that regard although it does make improvements with
reified types (generics that are retained at runtime for use in type checking
`is`--kotlin `instanceof`) and variance indicators.

------
k__
I have to damit, I wish Ceylon would have won, hehe.

------
brianwillis
> If a lambda has only one parameter then its declaration can be omitted
> (along with the ->). The name of the single parameter will be "it".

> val notPositive = not {it > 0}

This idiom took me by surprise. It's really quite lovely, and now I'm
disappointed C# doesn't include it.

~~~
pvdebbe
The schools for and against anaphoric syntax constructs are pretty divided
50-50. "It" is certainly better than scala's underscore.

------
_pmf_
I'm a bit disappointed that there's no metaprogramming support in Kotlin. Even
Groovy had some AST-level transformators. Maybe we'll get some high-level API
for writing APT-level tools in Kotlin itself ...

~~~
marcofiset
If you're looking for metaprogramming on the JVM, and like the semi-functional
approach of Kotlin, you should definitely take a look at Clojure.

~~~
killin_dan
I hate clojure, but that complaint is EXACTLY what I was thinking must drive
clojure users to it in the first place. Clojure just seems dumb because the
jvm is such a hassle and bloated, sbcl is incredible, racket is good, guile is
incredible, etc plenty of other lisp environments, why waste time on java?

I hope kotlin native is as good as scala native. I don't care about kotlin vs
Java, but kotlin vs scala native is HUGE to me.

------
skdotdan
Kotlin is the new Swift/Golang #hype

~~~
IshKebab
Not really, it's more like "Oh my god we don't have to use Java any more". I
don't think it is particularly loved on it's own, it's just much better than
Java.

Swift is similar in that iOS developers don't have to use Objective C any
more, but actually looks like a nice language in its own right.

I think although Kotlin is going to be an improvement for Android development,
it's not going to change much unless Google drastically simplify the actual
Android API. You're still going to have to deal with this shit:
[https://github.com/xxv/android-lifecycle](https://github.com/xxv/android-
lifecycle)

~~~
lucidguppy
Wasn't scala supposed to do that?

------
fixermark
To a first approximation, it seems like

Java : Kotlin :: JavaScript : TypeScript

This seems like a good idea.

------
seanalltogether
Does it have an equivalent to Swifts if let clause?

    
    
        if let person = selection?.organization?.owner {
            setTitle(person.name)
            setImage(person.image)
        }

~~~
asadmshah
Yes.

    
    
        val person = selection?.organization?.owner?.let {
            setTitle(it.name)
            setImage(it.image)
            it
        }

~~~
seanalltogether
ok so I'm guessing you can't operate on more then one scope at once?

    
    
        if let person1 = dashboard?.owner, person2 = selection?.organization?.owner {
        	person1.cloneProperties(person2)
        }

~~~
kodablah
You'd use nested let clauses and name the param instead of using the implicit
"it"

~~~
meddlepal
Or just write a function to accomplish the same behavior:
[http://stackoverflow.com/a/35522422/364135](http://stackoverflow.com/a/35522422/364135)

Would be nice if there was a multiLet in the stdlib. Probably something that
happens eventually anyways.

------
partycoder
This webcomic explains it better than I ever could:
[http://abstrusegoose.com/249](http://abstrusegoose.com/249)

------
rasjani
Tried Kotlin few days ago. Started from "official" install docs and it said
that it's just 'brew install kotlin". Yeah, it worked just fine but it would
have been way nicer if they would have mentioned that you should also have
Java 1.6 for compiler to actually work.

------
stewbrew
I think the language is quite nice but the tooling is lacking (if you don't
use intellj idea). Even the official eclipse plugin has many rough edges. So,
when learning kotlin, you effectively also have to learn an ide if you're not
already an idea user.

------
lucidguppy
So with python I have virtual env. With elixir I have mix. For javascript I
have npm.

What do I have for kotlin?

~~~
e12e
Maven?

------
StrykerKKD
It's interesting how many language wants to be part of the ML family or at
least look like an ML language.

Kotlin has a really nice and simple syntax compared to Scala, which has way to
many features.

------
maaaats
Kotlin is more than just simpler java-syntax, though. If you want to really
take advantage of it, there's new idioms, you can use it as a typesafe dsl
etc.

~~~
Grazester
Easier syntax??!!

------
neoncontrails
Could someone paraphrase the argument for learning Kotlin? I understand it's
essentially Jetbrain's fork of Java, motivated to some degree by the desire to
provide useful realtime information to programmers working in the Jetbrains
ecosystem. Presumably this implies that certain features present in Java that
are ambiguous at compile time (e.g. generic types) might be winnowed away in
the pursuit of a language more conducive to static analysis?

~~~
justsid
It’s not a fork of Java, it’s a language that uses the JVM like Scala. It’s
not at all like Java, it’s a modern language more akin to Swift with lots of
syntactic sugar.

------
ausjke
Does Kotlin have its own class/libraries or it still uses Java's classes?

~~~
sedro
Kotlin has its own standard library

~~~
mike_hearn
It's both.

Kotlin's standard library is tiny. It consists mostly of extension functions
and aliases over the Java standard library. For instance kotlin.String is just
an alias to java.lang.String, it's exactly the same object. Kotlin's lists are
just more type safe views over java.util lists. Much of Kotlin's standard
library is in fact inlined and then optimised, so using it doesn't even create
function calls in your bytecode.

So whilst Kotlin does technically have a standard library, to do anything
practical you'll be using Java's. And that's one reason why we like it. No
duplicate standard library to learn.

------
alexellisuk
Does anyone know the official docker image for Kotlin or are we too early for
that?

------
maxpert
I knew this will show up ASAP I heard the Kotlin support news :P

------
Elrac
Language quibble:

> "Function arguments are specified in brackets after the function name."

No they're not! They're specified in PARENTHESES after the function name.

~~~
hexomancer
[https://en.wikipedia.org/wiki/Bracket](https://en.wikipedia.org/wiki/Bracket)

------
grabcocque
It looks like there's been a very conscious effort to strike a midpoint
between Java's familiar clunkiness and Scala's hipster experimental side.

I think that's a good thing, you end up with a language that feels pragmatic
and powerfully practical.

~~~
mejari
I've been told that a big selling point for Kotlin is that it was developed
from actual usage and production rather than some of the more academic
languages solving abstract (although still interesting) problems that day-to-
day developers may not care much about.

~~~
piaste
The Henry Ford quote about faster horses comes to mind.

~~~
romanovcode
You're trying to tell us that Scala is something better and we are just too
stupid to understand it's power/beauty/importance?

~~~
hocuspocus
Scala is undeniably more powerful overall (beauty and importance are
subjective).

It's also used by companies like Verizon, SAP, IBM, Walmart ... not exactly
hipster research labs.

------
gcb0
the whole kotlin debate is just a misguided stab at solving the pain that is
programming for android.

everyone everywhere hates android dev work. so they think that it must be
java. no, java sucks, but kotlin sucks just the same. the problem is the
android ecosystem as a whole. the ever changing apis. etc.

wasting time on java vs kotlin is absurd with so many other real problems.

~~~
bitmapbrother
God, what a useless post. If you don't like Android development don't waste
your time with it.

~~~
h1d
Criticism can be useful if constructive.

~~~
dragonwriter
But that criticism wasn't constructive, so...

~~~
gcb0
it was constructive in the sense that the debate waste time from the real
issue. But feel free to keep adding noise and fighting for syntax sugar.

------
alexfi
Kotlin - The Force Awakens

~~~
donpdonp
Kotlin - The Source Awakens

~~~
alexfi
Haha this one is even better.

