Live data from Hacker News

Learn Kotlin in Y Minutes

learnxinyminutes.com

71–80 of 239 posts

Re: Learn Kotlin in Y Minutes

#71

Does it have an equivalent to Swifts if let clause? if let person = selection?.organization?.owner { setTitle(person.name) setImage(person.image) }

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

You may use `also`. It is like let but it returns the receiver.

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

Re: Learn Kotlin in Y Minutes

#72
post #22

Earlier quoted context omitted.

Come on. This is not about actual production stuff. It's new! It's cool! That's pretty much it.

No so. Many people use it in production. The language has been around for 7 years and a stable 1.0+ release for over a year. It's very much more mature than swift and rust and certainly sibling to go in that regard.

I tried to explain exactly this before and a lot of people didn't get it. 1.0 doesn't mean anything, JetBrains spent so much time to make something stable and good. That is why kotlin didn't suffer of the big changes swift suffered since its 1.0. (because kotlin suffered those changes before 1.0)

Re: Learn Kotlin in Y Minutes

#73

> 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?

It's obviously very strongly influenced by Scala, to the point of adopting a number of its syntax decisions that are considered questionable (procedure syntax, infix notation, "=" function definitions).

I will echo what the others have said; it's not what I would choose, but in practice it's never been a problem when I'm writing Scala.

Re: Learn Kotlin in Y Minutes

#75

> 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?

My guess is it came from Scala? In practice it's not very tough to get it right.

Val might have originally been OCaml or Haskell.

Re: Learn Kotlin in Y Minutes

#76
post #48

Earlier quoted context omitted.

Somehow that seems even less readable to me.

This is simply "parentheses in a call can be omitted entirely if the lambda is the only argument to that call." This one feature allows for type safe DSL's which eases GUI construction on Android and other domains. https://github.com/Kotlin/anko/wiki/Anko-Layouts Its also used for chaining stream code which takes in functions. You get used to this feature very quickly.

It's actually "if the lambda is the last argument in the call you can close the parens after the penultimate argument".

Re: Learn Kotlin in Y Minutes

#77
post #48

Earlier quoted context omitted.

This is simply "parentheses in a call can be omitted entirely if the lambda is the only argument to that call." This one feature allows for type safe DSL's which eases GUI construction on Android and other domains. https://github.com/Kotlin/anko/wiki/Anko-Layouts Its also used for chaining stream code which takes in functions. You get used to this feature very quickly.

I know what it is, I'm just saying that in a Java-esque language, omitting parens for function application feels worse than doing so in eg Haskell or even Ruby.

Swift also supports trailing closures. It's a concept that's become pretty familiar of late.

Re: Learn Kotlin in Y Minutes

#78

Earlier quoted context omitted.

Official support still matters. There is some inherent risk whenever you go in a direction not explicitly supported by the owner of your platform, and now that risk is gone.

Not only does official support matter, it matters much more than whether or not the language is good. I keep learning that lesson again and again in the hard, painful way.

As a new developer I'd like to hear more about why this is?

Re: Learn Kotlin in Y Minutes

#79
post #16

Earlier quoted context omitted.

Also because some of us absolutely needed a break from java.

Still looks like Java.

Not even a bad thing. It's a pragmatic JVM language. It's 100% interoperable with Java without baggage like Groovy has. It's probably going to look like Java. Scala can look like Java if you write it very imperatively. What's nice about Kotlin is that the language supports idioms that allow you do diverge from "looking like Java" as you write it more.
Post reply on HN