Live data from Hacker News

From Java to Kotlin and Back Again

allegro.tech

111–120 of 199 posts

Re: From Java to Kotlin and Back Again

#111
post #27

TypeScript also has the weird reversed type declaration. I've never understood it; it's so much less natural to read. Having the type first allows you to easily mentally parse it as "A Foo named bob".

And then there are those of us who simply don’t want to see the “Foo” (type) part at all, just Bob (the name).

Others have mentioned the Pascal / Modula / Eiffel type languages, I’m sure, as well as even newer languages that do type inference.

I wanna see the name of the thing on the left margin, rather than AbstractBoilerPlateFactoryFactoryFactory. Or maybe, I don’t even wanna see the thing at all, and just evaluate an expression as a parameter to a function :-)

Re: From Java to Kotlin and Back Again

#112
post #79
post #46

Earlier quoted context omitted.

Heinz is American (and, in the context of the article, a global brand), not Russian.

Sure, it's about the (negative/funny) association. I was recently told about persistent animosity between Poles and Russians; it crossed my mind given JetBrains is a Russian company masquerading as Czech. BTW, I also think that the name "Kotlin" is the worst aspect of the language, especially when you hear how is it pronounced by the authors in Russian. Big plus for language/runtime/transpiler features, big minus for…

Kotlin the ketchup raises perfectly positive associations for an average Pole. It's a household name, and a company with a nearly century-long tradition under its belt!

The authors wanted to name it after a Russian island (as a nod to Java); if you browse the names, some other possibilities were Iturup, Urup, Sakhalin, Kolguyev, Paramushir... :) Kotlin ain't so bad, then

Re: From Java to Kotlin and Back Again

#113

I work in Kotlin and Java and have opinions on both. Some feedback... I disagree about the name shadowing issue. In fact, I wish Kotlin didn't suck so hard and not allow me to ignore those warnings specifically. My primary use for name shadowing is so that I don't use the previous variable. This may be a bit strange, but in highly functional contexts with immutable variables, shadowing a name is reasonable especially…

Optionally ignoring thread safety seems indefensible -- until you can go full COM and declare your package apartment-threaded, working in a mutable language with uncontrolled multi-threading is the deal with the devil you've made and code that doesn't embrace that reality is just broken. Agree about the shadowing. var x_2 = f(x_1) // never use x_1 again for anything deserves its own syntax and compiler checks

> Optionally ignoring thread safety seems indefensible

Nobody forces everything to be thread safe. That would either be suicidally complex or suicidally slow. The problem isn't so much "ignoring thread safety", it's that this:

  class Foo(var thing: Int?) {
    fun doSomething() {
      if (thing != null) {
        thing++
      }
    }
  }
doesn't compile and it should. It fails to compile claiming that 'thing' could have changed in the meantime, so it can't safely assume non-null. However, that can only happen if Foo is accessed from multiple threads, but this isn't thread safe nor pretending to be in the first place. You can make the compiler happy by doing this:

  class Foo(var thing: Int?) {
    fun doSomething() {
        val t = thing
        if (t != null) {
            thing = t + 1
        }
    }
  }
But of course that's not remotely thread safe, either. It wasn't thread safe to begin with, and it's still not thread safe now. But this will of course compile just fine. You're forced to jump through hoops to workaround compiler "bugs"

To be fair here the warning isn't actually about thread safety at all, it's to guard against something like this:

  class Foo(var thing: Int?) {
    fun otherThing() {
        thing = null
    }

    fun doSomething() {
        if (thing != null) {
            otherThing()
            thing++
        }
    }
  }
Kotlin has so far just been unwilling to allow the compiler to handle the cases where it could prove that the variable hasn't been modified in the meantime because they can't always prove it.

Re: From Java to Kotlin and Back Again

#114

To add to the authors list: time kotlinc Hi.kt user 4.5s !! (OK IN IDE on second run) trailing comma not allowed no python like package manager. import mail? no a = b = 1 // assignments are not expressions

No package manager? You can use Maven, Gradle, whatever.

Re: From Java to Kotlin and Back Again

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

At the concrete/immediate level, a nice way to do error handling when you want errors to include a detail message (i.e. a Result/Either-like) - most languages that offer Option-like types let you use a type like that the same way, but in Kotlin the nice ?. syntax only works for "null". Even Java checked exceptions are a better answer for that use case than anything in Kotlin.

Proper immutable types for e.g. collections. If you're writing in a functional style as Kotlin encourages, you want to be able to write functions that accept lists that are required to be immutable, not just lists that the function isn't going to mutate itself. (Scala's collections get a lot wrong but a thing they get right is that e.g. scala.collection.List is a mutable-or-immutable interface that offers only read methods, and then scala.collection.mutable.List and scala.collection.immutable.List are subtypes for mutable and immutable. Kotlin offers the equivalent of scala.collection.List but not the equivalent of scala.collection.immutable.List)

Better support for operations that need to happen in particular contexts - i.e. custom command-like objects. Kotlin has a bunch of syntaxes that could be reused for this - .?, async/await, and plain old collection iteration all need similar syntax, but there's no way to overload a syntax like that for your custom type. (Scala gets this right: for/yield works for options, for async, for plain old collections and more, but also works for user-defined types).

And ultimately, higher-kinded types. (More concretely: the ability to write utility functions like "traverse" that will work the same for various different context-like types).

Re: From Java to Kotlin and Back Again

#116
post #74
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…

I feel the same way: author wants Java and was hoping only for a better Java: compatible with most patterns, tools, even libraries, but addressing some of his pet frustrations. When Kotlin did not satisfy his hopes he got disappointed. Understandably, but I do not see it as the Kotlin problem. The other problem I have with this post is that it did not state desires/hopes up front. The intro only mentions compile-time…

> a better Java: compatible with most patterns, tools, even libraries, but addressing some of his pet frustrations.

But is this a main pitch of Kotlin?..

Re: From Java to Kotlin and Back Again

#117
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…

Why would you use Java when you could use C++ which has a ton of extra features? Or Haskell which has a lot of neat abstractions? Or Python which is super easy to use? Or Lisp which is extremely flexible?

Simple, they all serve a particular purpose. Scala serves a particular purpose, so does Kotlin.

I have found Kotlin to be an easy to use modern language which the JVM ecosystem was IMO lacking. That said, I am not a Kotlin advocate. I’d use if I had to choose from the JVM languages. Otherwise there are plenty of other languages and ecosystems to choose from.

No one likes small enhancements over an existing language in a new language - it is usually not worth switching over. Remember D? IMO, Kotlin developers have made sensible choices in most cases while retaining full Java interop - something I consider an achievement.

Re: From Java to Kotlin and Back Again

#118
post #34

My 5 cents: It seems to me that the author did not spent enough time to learn Kotlin. The way he mixes Java types (Integer.parseInt) inside pure Kotlin code and then complains about lack of Null-Safety? It is enough to use an extension function String.toInt() to stick to Null-Safety and compiler will do the rest. His main() function? Another weird argument because Kotlin's documentation has some examples on how to wr…

There is some value to the criticism where it's easy for Java programmers to do the wrong thing because it's possible when they shift over. Of course, that's the price you pay for compatibility with Java, but maybe there should be tooling which can give warnings where you are using commonly abused Java tools where you'd be better off using Kotlin-specific ones.

There is, it's called IntelliJ.

Re: From Java to Kotlin and Back Again

#119
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…

> The colon operator is contextless

It has a type after. Always. Even assuming that's not enough for it to click, that Google search took all of 3 seconds and you are now typing ":" over "extends" thousands upon thousands of times. If you honestly thing one of those takes more time than the other, you haven't really thought this through.

This is a silly argument.

Re: From Java to Kotlin and Back Again

#120

Earlier quoted context omitted.

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.

Ah, I thought the author was comparing cpp to the part “which is already used to separate variable name from its type” which cpp does not do.
Post reply on HN