Live data from Hacker News

Learn Kotlin in Y Minutes

learnxinyminutes.com

111–120 of 239 posts

Re: Learn Kotlin in Y Minutes

#111

Earlier quoted context omitted.

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.

Never wrote any Groovy? Java developers had no problem picking this style up a decade ago.

Nope, never. Just coming back to the JVM ecosystem, actually, as I've been away since around the Java 7 release time (with the exception of some Jython work).

Re: Learn Kotlin in Y Minutes

#112

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

Rust has a pattern-matching "let" and then you can prefix names within any pattern with "mut" to make it mutable. So a basic mutable var is "let mut" but it's just a combination of two other features. I think it's a totally neat design.

Re: Learn Kotlin in Y Minutes

#113
post #84

Earlier quoted context omitted.

If your 'let' doesn't propagate so that immutable collections are used, it's not very valuable. Just like 'final' in Java doesn't prevent anyone from mutating your ArrayList. Using 'val' instead of something more suggestive like final/const/'not mut' seems a lot nicer to me. (Edit: and indeed Kotlin having "mutableListOf" and "listOf" separation is a good step in readability. The val/var before either of those is les…

That's a misnomer, not a misgiving. val/var/const/whatever only describe the reference, not the value. It doesn't really make sense for that annotation to, say, swivel a collection between ImmutableList and MutableList. Now, you might be right that it's confusing, this difference between reference mutability and value mutability. I see beginners struggle with it in Javascript's new let vs const all the time.

Even with Object.freeze() it only prevents mutation of the top-level keys.

Re: Learn Kotlin in Y Minutes

#114
post #5

Kotlin is the new Swift/Golang #hype

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

Re: Learn Kotlin in Y Minutes

#115

Earlier quoted context omitted.

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) }

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

Or just write a function to accomplish the same behavior: http://stackoverflow.com/a/35522422/364135

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

Re: Learn Kotlin in Y Minutes

#116
post #94

Earlier quoted context omitted.

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.

Why are Scala's "=" function definitions questionable? It makes absolute sense since a function should return a value.

For the same reason omitting braces in C-style-syntax conditionals and loops is questionable, i.e. misleading indentation.

As a bit of an unreformed code golfer and a fan of ML-style syntax, I actually kinda like it myself; I was just listing a few things that are "considered questionable" (by some people) and present in both languages.

Re: Learn Kotlin in Y Minutes

#117
post #94

Earlier quoted context omitted.

Why are Scala's "=" function definitions questionable? It makes absolute sense since a function should return a value.

They might be referring to the update methods: val array = new Array[String](10) array.update(7, "hello") array(7) = "hello" // simply calls out to update

I still fail to see what makes this questionable. It's just syntactic sugar that you don't even need to use, and which is pretty clear when you see it in the wild.

Re: Learn Kotlin in Y Minutes

#118
post #84

Earlier quoted context omitted.

If your 'let' doesn't propagate so that immutable collections are used, it's not very valuable. Just like 'final' in Java doesn't prevent anyone from mutating your ArrayList. Using 'val' instead of something more suggestive like final/const/'not mut' seems a lot nicer to me. (Edit: and indeed Kotlin having "mutableListOf" and "listOf" separation is a good step in readability. The val/var before either of those is les…

> * If your 'let' doesn't propagate so that immutable collections are used, it's not very valuable.* That's nonsense. 1. You cannot implement immutable collections without `let` / `final` 2. The Java Memory Model has special visibility guarantees for `final` (which does propagate), making it really, really useful 3. Having the guarantee that a certain reference won't change is still useful even if the object referenc…

1. Sure you can, if you have encapsulation.

2. Java does a lot with the keyword 'final'. I guess here you're talking about the concurrency behaviors of it? Does it bother you that you can remove 'final' via reflection?

3. It's still useful (e.g. not needing to use yoda-style ifs in languages where you can assign inside an if expression Just In Case you forget an =), but not very. That's my whole point.

Re: Learn Kotlin in Y Minutes

#119

Earlier quoted context omitted.

Never wrote any Groovy? Java developers had no problem picking this style up a decade ago.

Nope, never. Just coming back to the JVM ecosystem, actually, as I've been away since around the Java 7 release time (with the exception of some Jython work).

I think you'll be pleasantly surprised how the ecosystem has changed. Legacy code is legacy code, but Java 8 changed a lot and people have mostly also adapted well to ideas coming out of the Scala / Groovy / Kotlin ecosystems primarily because there is just more of it and it's fairly familiar and common to run across libs and projects written those languages now if you're working in Java.

Re: Learn Kotlin in Y Minutes

#120
post #51

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/ And you don't need to install anythi…

It IS cooler, because everything that Google touches becomes gold, according to HN.

google gets a ton of criticism here
Post reply on HN