Live data from Hacker News

Learn Kotlin in Y Minutes

learnxinyminutes.com

41–50 of 239 posts

Re: Learn Kotlin in Y Minutes

#41

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

I'm personally a fan of the Rust way, i.e. `let` for const bindings and `let mut` for mutable ones. I think it's fairly clear which is which, and having to type four extra characters to get mutability helps reinforce the notion of const being the default choice.

Re: Learn Kotlin in Y Minutes

#42

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

Const exists too, but for compile-time constant. Var and val are ok due to the general conciseness of the language (they don't get lost in the noise of other ceremonies). Plus, being a language though to benefit from strong tooling, IDE's will generally display the two differently.

Re: Learn Kotlin in Y Minutes

#43

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

var = variable (can vary/change) val = value (constant) What can be mistaken?

At a quick glance one might mistake var for val since they're only one letter apart. The definitions do make sense though.

Re: Learn Kotlin in Y Minutes

#44
post #31

Earlier quoted context omitted.

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.

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

This is my litmus test to determine whether a modern language is not terrible. Why wouldn't you want to eliminate an entire class of errors?

Unfortunately, my day to day language at work is Go.

Re: Learn Kotlin in Y Minutes

#47

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

var = variable (can vary/change) val = value (constant) What can be mistaken?

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

Re: Learn Kotlin in Y Minutes

#48
post #19

Earlier quoted context omitted.

You can even get rid of the final parentheses. (1..100).map { it + 10 }

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.

Re: Learn Kotlin in Y Minutes

#49

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

In my experience as someone whose been writing scala for a couple of years (which also uses val/var), it has 100% never been confusing or a problem.

Re: Learn Kotlin in Y Minutes

#50
post #8

Earlier quoted context omitted.

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.

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.

A wide array of quality of life changes to Java.

> The fact that things are shorter to declare doesn't make it better.

This is debatable. In fact, shorter code could (but not always, of course) mean less room for error and more room to hold higher abstractions. Boilerplate is a less efficient use of cognitive energy.

Post reply on HN