Live data from Hacker News

Learn Kotlin in Y Minutes

learnxinyminutes.com

201–210 of 239 posts

Re: Learn Kotlin in Y Minutes

#201

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.

I've been doing few projects with it and find it very lovely. Interop with Java works flawlessly in my experiences and RxKotlin extending RxJava makes that side work nicely as well. For one project[0] I used Ratpack as the web tier and that with Guice locked in place very easily. DB side of things I have used Kotlinquery which did its job nicely for my small use case.

In another I used Spring Boot where Kotlin felt like a native in that environment.

I'm guessing if you are building something with ORMs or similar where Java Bean convention is needed, you might lack the beauty of immutability and data classes (there are workarounds though) but other than that most pieces drop in place without a hitch.

0: https://github.com/Xantier/trycatch

Re: Learn Kotlin in Y Minutes

#202

Earlier quoted context omitted.

It's not redundant; for example let (mut x, y) = (1, 2); x is mutable, y isn't. That is, let is the way that you introduce a new binding, always.

Am I being a complete noob that only knows Python (I am) if I ask: Why do you need to declare that something is a mut or string or whatever? Python doesn't seem to need such extra lines with obvious declarations.

A couple important benefits (there are many others, as well as drawbacks) are

1) the compiler can then warn you when you violate your own declarations before the code is ever run. e.g. it can tell you that you've mutated something you said you didn't want to, or that you've taken the sum of an int and a list.

2) the compiler can guarantee certain things at compile time and thus eliminate the overhead of checking them at runtime. since a value in Python can be anything, before performing a string operation on a string the python runtime must first check that it is a string, while the runtime of a language like rust can assume that it is because that was guaranteed at compile time.

Re: Learn Kotlin in Y Minutes

#203

Earlier quoted context omitted.

I agree with making mutability require more typing, although I'd prefer going without the redundant `let`.

It's not redundant; for example let (mut x, y) = (1, 2); x is mutable, y isn't. That is, let is the way that you introduce a new binding, always.

Not OP, but why do you need the 'let' at all? Why not x = 7 mut y = 3 ?

Re: Learn Kotlin in Y Minutes

#204
post #168
post #162

Earlier quoted context omitted.

I'm guessing the parent is just complaining that if you are reading code very fast (particularly if you're browsing repositories on your phone) it is hard to distinguish between "val" and "var."

Let alone type them wrong on a tired night.

It's even worse when your primary keyboard is Dvorak!

Re: Learn Kotlin in Y Minutes

#206
post #9

In terms of why we'd want to, there is this note here: https://kotlinlang.org/docs/reference/comparison-to-java.htm... 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?

I've used Kotlin a bit. I can't say anything bad, things just work. That said, idiomatic Kotlin differs from idiomatic Java, so some wrappers are nice to have. And it's really sad, that Jetbrains ditched idea to automatically infer nullability from bytecode, I hope, they'll revisit this decision in the future.

Re: Learn Kotlin in Y Minutes

#207

Earlier quoted context omitted.

Am I being a complete noob that only knows Python (I am) if I ask: Why do you need to declare that something is a mut or string or whatever? Python doesn't seem to need such extra lines with obvious declarations.

Dynamic languages can convert types in runtime (so 1 + "f" = "1f") and not so many languages (not only dynamic) cares about mutability.

This is weak typing not dynamic typing.

1 + f in modern Python results in a ValueError.

Re: Learn Kotlin in Y Minutes

#208

> 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 bet you can change the val color to something that contrasts the var color in an IDE.

The IDE underlines mutable variables at both definition and use sites. Values are not underlined. It's a perfectly fine way to visually distinguish them.

Re: Learn Kotlin in Y Minutes

#209

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.

Yes. I lead a team that's writing a new piece of what can be thought of as enterprise middleware in Kotlin:

https://github.com/corda/corda

It's a distributed ledger/blockchain system being written for large, conservative banks and is around ~90%+ Kotlin code.

There's not much to say about it, it works fine, I wrote about it here:

https://www.reddit.com/r/programming/comments/6bqo7n/kotlin_...

Re: Learn Kotlin in Y Minutes

#210
post #104

Earlier quoted context omitted.

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.

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

Because "to" isn't actually syntax at all. It's an infix function that creates a Pair. You can alt-click it in the IDE to go to the definition.
Post reply on HN