Live data from Hacker News

From Java to Kotlin and Back Again

allegro.tech

101–110 of 199 posts

Re: From Java to Kotlin and Back Again

#101
post #66

"Kotlin changed the extends keyword into the : operator, which is already used to separate variable name from its type. Back to C++ syntax? For me it’s confusing." Not only C++; C# also. It's not very hard to confuse the author, is it :) I understand it's different from Java he's used to, but that doesn't mean one can hold every such difference against Kotlin. Not being Java isn't in and of itself a fault of a langua…

>Why is ":" problematic exactly? It's more concise. Anyone, including non-java programmers, can make an educated guess at what the "extends" keyword does to a java class. The colon operator is contextless. Unless someone tells you or you've coded in c++/c#, you can't know for sure what it means without googling it. Here's a case in point, my biggest bugbear with the nim documentation. When you first see nim code, you…

"If you had to write "extends" in kotlin instead of use a colon, how often would you be doing it?"

Certainly more often than you'll need someone to tell you what ":" in a class declaration does ;)

I see your point, I just don't think this language trait deserves to rank as "confusing" for a professional programmer.

While we're at it, Kotlin, unlike Java, provides explicit "constructor" and "init" keywords. So if it loses points for the lack of "extends", why doesn't Java for not having these?

Nim's manual doesn't seem helpful indeed (they acknowledge it openly in the beginning), but I feel this is sort of beyond the point.

Kotlin's docs are very clear and exhaustive. Case in point - as we discussed inheritance declarations - https://kotlinlang.org/docs/reference/classes.html

Re: From Java to Kotlin and Back Again

#102
post #66

"Kotlin changed the extends keyword into the : operator, which is already used to separate variable name from its type. Back to C++ syntax? For me it’s confusing." Not only C++; C# also. It's not very hard to confuse the author, is it :) I understand it's different from Java he's used to, but that doesn't mean one can hold every such difference against Kotlin. Not being Java isn't in and of itself a fault of a langua…

OK, so I’m used to : from doing Pascal back in the 80s, but anyway.

Read the colon as “is a”, and it makes sense.

“counter is a number”

“DogClass is a (special) MammalClass”.

Not seeing a problem there, but again, I have no particular love for curly brace languages. And I would MUCH rather see the type expression spewage AFTER the symbol name - especially given Java 5 generic declarations mixed with Java 8 lambda declarations (yuck!).

Re: From Java to Kotlin and Back Again

#103
post #61

Earlier quoted context omitted.

JSON doesn’t support non-String keys, for one thing.

JS does

Actually no, all keys are strings in JS, and if you use something that isn't a string as a key, it is converted to a string (unless you meant Maps[1], which don't use object notation).

[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/...

Re: From Java to Kotlin and Back Again

#104
post #99
post #45

Is it me, or does the article feel like it is written by someone who didn’t actually bother to learn Kotlin. Instead they learnt the bare minimum syntax and tried to write Java in Kotlin. The author complains a lot about how Kotlin is different from Java. Err.. it is a new language — it is supposed to be different — otherwise why bother? > I have my favorite set of JVM languages. Java in /main and Groovy in /test are…

> The author complains a lot about how Kotlin is different from Java. Err.. it is a new language — it is supposed to be different — otherwise why bother? Kotlin advocates try to have it both ways. If it's a full new language, to be evaluated as a full language, then why would you adopt it when it's missing important features compared to Scala? The narrative is that it's a set of small enhancements to Java that are ea…

> then why would you adopt it when it's missing important features compared to Scala

Such as?

Re: From Java to Kotlin and Back Again

#105
post #66

"Kotlin changed the extends keyword into the : operator, which is already used to separate variable name from its type. Back to C++ syntax? For me it’s confusing." Not only C++; C# also. It's not very hard to confuse the author, is it :) I understand it's different from Java he's used to, but that doesn't mean one can hold every such difference against Kotlin. Not being Java isn't in and of itself a fault of a langua…

And that’s not even how C++ uses the colon!

What do you mean? C++ does use a colon for inheritance in exactly the same way as Kotlin.

Re: From Java to Kotlin and Back Again

#106
post #99
post #45

Is it me, or does the article feel like it is written by someone who didn’t actually bother to learn Kotlin. Instead they learnt the bare minimum syntax and tried to write Java in Kotlin. The author complains a lot about how Kotlin is different from Java. Err.. it is a new language — it is supposed to be different — otherwise why bother? > I have my favorite set of JVM languages. Java in /main and Groovy in /test are…

> The author complains a lot about how Kotlin is different from Java. Err.. it is a new language — it is supposed to be different — otherwise why bother? Kotlin advocates try to have it both ways. If it's a full new language, to be evaluated as a full language, then why would you adopt it when it's missing important features compared to Scala? The narrative is that it's a set of small enhancements to Java that are ea…

> then why would you adopt it when it's missing important features compared to Scala?

What important features are missing?

Re: From Java to Kotlin and Back Again

#108
post #101

Earlier quoted context omitted.

>Why is ":" problematic exactly? It's more concise. Anyone, including non-java programmers, can make an educated guess at what the "extends" keyword does to a java class. The colon operator is contextless. Unless someone tells you or you've coded in c++/c#, you can't know for sure what it means without googling it. Here's a case in point, my biggest bugbear with the nim documentation. When you first see nim code, you…

"If you had to write "extends" in kotlin instead of use a colon, how often would you be doing it?" Certainly more often than you'll need someone to tell you what ":" in a class declaration does ;) I see your point, I just don't think this language trait deserves to rank as "confusing" for a professional programmer. While we're at it, Kotlin, unlike Java, provides explicit "constructor" and "init" keywords. So if it l…

>So if it loses points for the lack of "extends", why doesn't Java for not having these?

No one said it didn't :)

In general, I personally prefer my languages explicit for a variety of reasons. There's a balance for sure, and one can go too far the other way. For example, I find Rust to be a shade too unwieldy for my optimum preferences, although I would overlook that to gain the safety benefits if I had the right use case.

Re: From Java to Kotlin and Back Again

#109
post #99

Earlier quoted context omitted.

> The author complains a lot about how Kotlin is different from Java. Err.. it is a new language — it is supposed to be different — otherwise why bother? Kotlin advocates try to have it both ways. If it's a full new language, to be evaluated as a full language, then why would you adopt it when it's missing important features compared to Scala? The narrative is that it's a set of small enhancements to Java that are ea…

> then why would you adopt it when it's missing important features compared to Scala Such as?

There are a lot of things I miss. Case objects, macros, string contexts, (built-in) options as single-element collections, tuples, built-in either, abstract/self types, implicits, etc. We can argue about "importance" or even if those are good things, but we can't pretend that there aren't many missing features. Granted these days I appreciate Kotlin more than Scala, but that is more about tooling and backing.

Re: From Java to Kotlin and Back Again

#110

Ok, so, assuming that all the things he mentioned are just nitpicky, what's the upside of Kotlin over Java 10? Lots of people would need adequate training, perhaps some new tools and rewrites. There needs to be a serious upside to get a mainstream company to a niche language.

It's not worth it, Java is getting better and more feature rich that improves programmer productivity. Kotlin is like a cool JavaScript library in the market.
Post reply on HN