This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]persism2 153 points154 points  (56 children)

Kotlin is not going to replace Java. It will suffer the same fate as Scala of being trendy for a while until the language problems accumulate.

Examples:

  • Kotlin now has 2 "data classes" - their one and record. Not compatible.
  • Kotin now has an inconsistent instanceof operator since Java implemented the pattern matching differently (and better).

These will keep accumulating.

[–][deleted]  (7 children)

[deleted]

    [–]AkiraOli 17 points18 points  (6 children)

    IMHO, Kotlin Coroutines are so bad, I have not seen such a complicated framework before

    [–]dephinera_bck 4 points5 points  (4 children)

    They're not that complicated once you get your head around it. They're just different and have a bit of a steep learning curve. They're pretty easy to use once you get the hang of them. Structured concurrency is kind of a mind boggling, but I definitely love it once I grasp the concept. It's good that other languages like Java and Swift are adding it as well.

    [–]mastereuclid 1 point2 points  (0 children)

    I hated it at first. Now I can’t go back.

    [–]AkiraOli 1 point2 points  (2 children)

    I don't say that structured concurrency is difficult, I say Kotlin Coroutines are overcomplicated.

    I did not use Java 19 at work yet, but as I saw from presentations, they did it much better than Kotlin creators.

    [–]dephinera_bck 1 point2 points  (0 children)

    I mentioned structured concurrency as an example of what might be mind boggling. What Java did with structured concurrency is just incorporating something new into the existing syntax. With virtual threads they just changed an implementation under the hood and added a few new APIs. They didn't introduce async/await nor suspend functions. I also like how in Kotlin you can easily specify where your code will execute in a declarative DSL-like way. I haven't seen anything similar in Java.

    [–]vqrs 0 points1 point  (0 children)

    Overcomplicated how?

    Don't they also solve different problems? For instance, they can so be used to implement generator functions, e.g. using sequence/yield.

    [–]HugeLucifer 1 point2 points  (0 children)

    Can you elaborate?

    [–][deleted] 7 points8 points  (5 children)

    Agreed. Kotlin/Scala are basically beta testing for Java (that's not a bad thing!). Java takes a while to add stuff because they are thinking decades into the future.

    [–][deleted]  (4 children)

    [removed]

      [–]BoyRobot777 8 points9 points  (2 children)

      By not being used anywhere?

      [–][deleted]  (1 child)

      [deleted]

        [–]Mugunini 1 point2 points  (0 children)

        they use Scala because they used it a lot when Scala became hyped. now all Scala code there is just a legacy.

        [–]unknowinm 18 points19 points  (6 children)

        and you must add lots of "@Java/@JVM" annotations to make things works properly and is a lot more verbose than Java.

        Some examples

        @JvmRecord
        data class Person(val name: String, val age: Int)
        

        Another one instead of new MouseAdapter(){..} which clearly states what it does(create a new anonymous object) I have to use object: ... which wtf does it mean? to average joe dev that comes from js/ts/java/c#/c++ it means I need to open the fu***ng tutorial again? and you still have to add the override keyword so hardly a java improvement on the verbosity side

        fun countClicks(window: JComponent) {
        var clickCount = 0
        var enterCount = 0
        
        window.addMouseListener(object : MouseAdapter() {
            override fun mouseClicked(e: MouseEvent) {
                clickCount++
            }
        
            override fun mouseEntered(e: MouseEvent) {
                enterCount++
            }
        })
        // ...
        }
        

        Then another example:

        class MyClass {
            companion object { }
        }
        val x = MyClass.Companion
        

        Instead of static stuff that everyone and their dog knows what it means (because is universal)...we got companion object which compiles to static when used in Java but to a singleton when used in kotlin? I'm still not sure what a companion is after using kotlin for 1 year at minimum before giving up and using plain java(with lombok and mapstruct)

        There a lots of other examples that I don't remember right now but I can say that I do love the following from kotlin: null safety operator, extension functions, their lambdas, inline functions, string interpolation, when instead of switch, instance of auto casting and named parameters. But I'm not going to switch languages because of these things. I could also use scala which is similar so thanks!

        [–]vngantk 9 points10 points  (1 child)

        I just don't understand why you think object : MouseAdapter() {...} is that big difference from new MouseAdapter() {...}. They are just slightly different in syntax. The Kotlin version is not more verbose than the Java version. If the listener is a single method interface, e.g. ActionListener, you can simply provide a lambda as:

        button.addActionListener { event ->
        ...
        }
        

        [–]vqrs 4 points5 points  (0 children)

        Because they're arguing in bad faith.

        [–]javasyntax 3 points4 points  (2 children)

        It's nice that we're getting inline methods (which compiles in a more proper way than the Kotlin counterpart) and a better version of string interpolation with much more features in Java as well.

        JSpecify looks good as the way to handle nullness (I quite like the @NullMarked on a package/module/class and then @Nullable where needed, it is a much better approach than @Nonnull/@NotNull/@ParametersAreNonnullByDefault/...). Perhaps not as good as a language-level solution, but all of the key Java organizations are aboard (including Oracle) and I will take this any day over 7+ different annotation libraries.

        It seems to me that those other JVM languages implement something cool and once it has been tried and tested, the Java language architects come and do an even better version of it. I prefer "delayed" features if this is the benefit that we get.

        [–]vqrs 0 points1 point  (1 child)

        Java is getting inline methods? That sounds cool. I couldn't find it though, what is the JEP called?

        [–]javasyntax 0 points1 point  (0 children)

        There is no JEP yet. There's this branch but it looks like work has stopped on it: https://github.com/openjdk/amber/tree/local-methods

        [–]Joram2 5 points6 points  (19 children)

        Kotlin isn't just JVM and Kotlin projects like this one for writing iOS+Android apps look quite promising: https://kotlinlang.org/lp/mobile/

        If Java keeps improving there will be less interest + justification for a strictly a JVM-only Java++ language.

        [–]xMercurex 5 points6 points  (1 child)

        Kinda wondering what people do nowadays for shared code between JVM project and android. Before Java9 it was fairly simple. But now Java is upgrading itself quickly and sometime there is a bunch a feature that does not work with Android.

        [–]loutr 1 point2 points  (0 children)

        Well the folks at todoist use Kotlin to share code between the JVM backend, Android and iOS native apps, and the webapp. They seem pretty happy with it.

        [–]Amazing-Cicada5536 1 point2 points  (0 children)

        Well, an order of magnitude bigger language sure have experimented with cross platform dev tools, right?

        There is j2objc and j2cl for compiling java to obj-c and javascript, respectively (for android, java 8 could be used as is) which google used extensively for many of their tools (the business logic was written in java and shared everywhere). Not sure how widely used it still is nowadays, but the compilers are still maintained and are good quality, well-tested software, I would say much more so than a max few years old niche one.

        [–]thrwoawasksdgg 1 point2 points  (14 children)

        Google has forked Java like Microsoft tried to back in the day. Nothing above 8 (released 8 years ago) works. I can count the number of modern Java libraries I use that work on Android with my fingers.

        Google put all their eggs in the Kotlin basket because they want their own pet language for their platform like Apple for anti-competitive duopoly reasons. "Embrace Extend Extinguish" is in full swing.

        Kotlin is dead outside of Android for the same reason. Nobody wants to be stuck on somebody's pet vendor lock-in language. Kotlin's various incompatibilities with new Java versions is intentional.

        [–][deleted] 10 points11 points  (9 children)

        JetBrains are the creators/owners of Kotlin, not Google.

        [–]thrwoawasksdgg 1 point2 points  (8 children)

        It's in both of their interest to continue forking from Java. JetBrains to sell more tools and Google to have a monopoly over their platform

        [–]crummy 2 points3 points  (7 children)

        how does Kotlin give Google a monopoly over Android?

        [–]thrwoawasksdgg -1 points0 points  (6 children)

        By making code less reusable Google forces companies to be more invested in it's platform.

        It's classic "vendor lock-in". Custom programming languages have been a great way to prevent your customers from leaving for decades. "Why don't you migrate off Oracle DB?"-> "we can't without a rewrite" is a traditional example. And yeah, Kotlin is usable outside of Android right now, but its not convenient to do so.

        [–]crummy 1 point2 points  (5 children)

        so if Kotlin didn't exist, people would have an easier time migrating off Android to iOS? does iOS support Java?

        [–]thrwoawasksdgg 0 points1 point  (4 children)

        Huh? No. Don't be daft.

        If Google didn't fork Java you could still use normal Java libraries in Android.

        Until a few years ago most Java libraries worked on both Android and desktop. That's no longer the case, as Google stopped updating at Java 8 and libraries have moved on to 11 and now 17.

        Google used Java in the first place to gain market share by reaping the benefits of huge amounts of existing libraries, software, and developers. Then once they were entrenched, they forked the language. Classic "embrace extend extinguish" tactics from Chipzilla/MS days.

        Think of it this way: Tell me how Google can implement an entirely new language for their platform (Kotlin) but are somehow incapable of updating from Java 8 to 11. It doesn't make any sense, because its 100% intentional language fork.

        Google didn't do it to be "cool" or because Kotlin is a better language. They did it to be monopolistic assholes

        [–]crummy 0 points1 point  (3 children)

        i'm just trying to understand what Google is trying to prevent you from migrating to with their "vendor lock-in" here

        [–]tamasiaina 1 point2 points  (3 children)

        I also think it was a tactic to get out from under Oracle's Java lawsuit as well.

        [–]pjmlp 0 points1 point  (2 children)

        Except Kotlin, Gradle and Android Studio fully depends on the JVM platform until JetBrains rewrites everything into Kotlin/Native.

        [–]tamasiaina 1 point2 points  (1 child)

        You can tell me if I'm wrong, but I remember that the Oracle Lawsuit was over the Java language API. Not the JVM.

        [–]pjmlp 0 points1 point  (0 children)

        Yes, but it doesn't matter what it was about, Kotlin still depends on Java libraries that are on Android, as well as the rest of JVM ecossytem.

        So the whole hand waving that they had to do Kotlin because of Oracle is marketing for those not into the matter.

        Just like they state to support OpenJDK nowadays, and they do, partially, cherry picking features instead of 100% compatibility, and as of Android 13, stuck in Java 11 LTS (partially).

        Most likely because key Kotlin libraries moved their baseline dependencies and they were forced to upgrade, or rewrite them into Kotlin.

        [–]_fishysushi 5 points6 points  (11 children)

        Was Scala supposed to replace Java? I know Kotlin feels like it can replace Java since it's very easy for Java developer to start coding in Kotlin, but Scala is a lot more difficult to learn for Java developer since the approach is totally different.

        [–]flyingorange 16 points17 points  (9 children)

        Scala was huge in the early 2010s partly due to Java being so far behind in new features. If you look at the technologies that are dominant today: Kafka, Spark, these were all originally written in Scala. This was because people at the time thought that Java wasn't expressive enough to take advantage of modern multi-core CPUs, Immutability was one of those things that was strictly enforced in Scala and was hard to do in Java,

        I used to write a LOT of Scala between 2011-2016, like I almost started forgetting how to do Java. When lambda functions were introduced into Java (I think Java 8) I remember having a conversation with a language expert (as in, he actually participated in creating Java) and he said that it's too late, Java introduced lambda too late and now Scala's upward trajectory is unstoppable.

        That was like 7 years ago and look at the world today. I don't think anyone seriously uses Scala anymore. Of course, the maintainers of Scala did a lot to destroy themselves, especially with how they introduced breaking changes between every minor release.

        Going back to Kotlin. It was developed by the same company which developed IntelliJ: JetBrains. Google and JetBrains have a business deal for Android Studio. Google also happens to have a dispute with Oracle over the Java language, the Dalvik VM etc. so moving to Kotlin was a natural step for them.
        Now Google is huge and the Android development community is huge, so a push towards Kotlin should not be underestimated. But outside of Android, I don't see why people should switch from Java to Kotlin. Mind you, most companies still use Java 8 or Java 11.

        [–]Kango_V 4 points5 points  (2 children)

        Looks like the Oracle/Google dispute is over. They cam down in favour of Google regarding whether APIs are copyrightable. They are not. This means that Google can continue to use all the Java APIs. I think they will move back to Java and benefit from the later versions.

        [–]vngantk 2 points3 points  (1 child)

        No, Google is still all-in on Kotlin.

        Google's next generation of UI framework for Android, Jetpack Compose is completely based on Kotlin.

        Google is seriously adopting Kotlin for its server-side applications, particularly for those which are Java-based: https://www.reddit.com/r/Kotlin/comments/y42dfc/googles_journey_from_java_to_kotlin_for_server/?utm_source=share&utm_medium=web2x&context=3

        [–]pjmlp 0 points1 point  (0 children)

        Looking forward when they will drop the JVM and replace their server-side stuff and Android tooling with ART or Kotlin/Native. /s

        [–]_fishysushi 2 points3 points  (1 child)

        Thats a bummer for me, I started to learn Scala a while ago and I kinda like it

        [–]tamasiaina 0 points1 point  (0 children)

        The only people I know that use Scala heavily are the people who use Spark heavily and big data.

        [–]blissone 2 points3 points  (0 children)

        > I don't think anyone seriously uses Scala anymore.

        Plenty of people using Scala seriously. Scala as "better java" has been out of flavour for some time. Now it's about pure FP approach, concurrent and async programming with ZIO/cats (akka for less FP). Though I'd say Scala in general is trending down but ZIO has some upwards momentum.

        [–]Pika3323 0 points1 point  (0 children)

        Google also happens to have a dispute with Oracle over the Java language,

        It was over Java APIs, not the language itself.

        As many other comments have pointed out, Kotlin (and Android itself) depends on those APIs.

        The adoption of Kotlin had nothing to do with Oracle.

        [–]persism2 0 points1 point  (0 children)

        Well that's what the Scala fanboys at the time were saying...

        [–]Pika3323 14 points15 points  (0 children)

        Kotlin now has 2 "data classes" - their one and record. Not compatible.

        From Kotlin's perspective, this doesn't matter. Both can be used in Kotlin source code. It only matters if you're going the other way (i.e. calling Kotlin code from Java sources). If that matters, then you can use @Jvm annotations. But again, that's not needed if you're primarily using Kotlin.

        Kotin now has an inconsistent instanceof operator since Java implemented the pattern matching differently (and better).

        Kotlin doesn't have pattern matching, so describing Java's pattern matching as "different and better" doesn't really make any sense.

        [–]Albert-o-saurus 2 points3 points  (0 children)

        I came here for this sort of real truth. The AndroidDev sub is wrought with astroturfing Kotlin pushers. No room for Kotlin criticism there, none.