4 ms·
All the backend projects I work on were originally written in Java. I'll admit that Streams and Lombok make it a somewhat pleasant experience to work with, at l
by dlbucci 6y ago
All the backend projects I work on were originally written in Java. I'll admit that Streams and Lombok make it a somewhat pleasant experience to work with, at least compared to when I used it in college (I think Java 8 was newest?).
But that said, I once tried writing a new feature in Kotlin, and now all our code is Kotlin. I don't really see how Java can compete with the non-nullable types, data classes, and type-inferencing Kotlin gives you, with easy interoperability, to boot! (Although you might start regretting your use of Lombok at that point...)
- still_grokking 6y agoSame goes for Scala, where those Kotlin features come form originally.
- pron 6y agoThose features (except for nullability types) predate Java, let alone Scala and Kotlin, by a couple of decades. Those three -- like all programming languages -- get inspiration from similar sources. Java is just the most conservative of the three with regards to language features.
- ragnese 6y agoI think it's disingenuous to deflect by saying that Scala didn't invent those concepts. I think it's pretty clearly significant that Scala and Kotlin are JVM languages, specifically. If we just said "Well, StandardML had XYZ feature 30 years ago," you could reasonably wonder whether implementing those features on the JVM was a legitimate hurdle to not including them. But the fact that the guy who wrote generics for Java then went and created Scala with these features is telling. I also don't think that "Java is conservative" is the correct description of what's going on here. Look at the OP (I know you're a Java guy, so I don't mean that literally)- Java used to get maybe one language change for each major version until 16 where it got a bunch. Why? I don't know. But I think it's totally fair to observe two correlations in recent history: 1. Oracle obtained control of Java 2. Many other, very good, programming languages have been coming on the scene: Swift, Go, Rust, Kotlin, TypeScript, C#, F#. Even older programming languages have seen major advances in the last 5-10 years: C++ and PHP among them. I think it's pretty clear that Java just didn't feel the pressure to make itself better until recently.
- pron 6y agoYou're right about your main points: for some years before Sun's demise Java was neglected and lacked resources, and Oracle has gradually but significantly increased its investment in the platform. It is also true that the abnormality of ~2000-2005, when there were few popular languages, has ended. But the following two facts are also true: Scala didn't invent those features, and neither Kotlin nor Scala are big enough to be serious competitors for Java. So Java might be feeling the heat of competition, but not from those two, and, like all other languages, it looks around and borrows features, but not from those two more than others. It is possible that Java platform languages might indicate the palatability of certain features to Java programmers more than non-Java platform languages, and the Java language designers do have a closer relationship with the designers of other Java platform languages. But overall, these effects are not particularly big. Knowing the current designers of the language, I can say with certainty that Haskell has served as a bigger inspiration than either Kotlin or Scala on recent features and their design (inspiration, not direct source).
- brabel 6y agoI write a lot of Kotlin code but still tend to use Java a lot. All of the features you mention are not really an advantage for Kotlin anymore. Java has had tools to deal with nulls for a long time, we tend to assume everything is non-null unless annotated with `@Nullable` and let tools check correct usage at compile time... data classes are very similar to Java 16's records. Type-inference since Java introduced `var` is pretty much on-par with Kotlin. Some people have already started talking seriously about Kotlin now just adding friction, as you need to keep updating its version and the Gradle plugin (which is not compatible with some versions of Gradle if you're stuck with some old Gradle plugins). Java 17 should probably stabilize sealed classes, which is one of the biggest advantages of Kotlin at the moment... to be honest, even though I've always been a proponent of Kotlin, I am not nearly as enthusiastic now as I used to be about it.
- aphexairlines 6y agoYou can only assume non-null for your own code though. The java ecosystem of 3rd-party libraries will give you nulls, and most of the time won't include nullability annotations. var is a nice step, but encourages mutability since it's not final by default.
- ragnese 6y agoIf I remember correctly, it's fairly easy to use @Nullable and still end up with nulls there, even without an IDE warning. I'll have to double check to see if I can still reproduce that. But, to be fair, it's actually fairly easy to break Kotlin's null safety, too: https://blog.haroldadmin.com/circular-refs-kotlin/ https://blog.haroldadmin.com/circular-refs-kotlin/ But I basically agree with what you've said. Kotlin is certainly still a much more ergonomic language, but Java caught up fast recently. Kotlin 1.5 will be really cool, though, with the new value classes and the mutable methods feature (stolen from Swift).
- BoyRobot777 6y agoValue classes cannot provide the performance/memory flatness that Valhalla will bring though. So I'm not really sure what benefit does "values classes" bring. Just to make sure, you are talking about the inline class which is just a wrapper around single property? inline class Password(val value: String)
- vips7L 6y ago> data classes, and type-inferencing Kotlin gives you, You mean records and local variable type inference that are apart of Java? record SomeThing(int i, String s) { } var some = new SomeThing(2, "blah");