Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As pron always says.. that's a risk of staying on an LTS release. You're choosing to not receive updates.


It seems to me by design or by indifference Java is now tired of JVM ecosystem languages at large who claim innovation by surface level changes while relying heavily on JVM bedrock.

Now Java is moving fast and they are taking JVM compiler, runtime, class metadata etc along where Java, the language is headed.


Not only Java, that is the fate of all guest languages, as they don't evolve alongside the platform, always require additional tooling and most language cultures than start making their own little islands of idiomatic libraries instead of directly using platform libraries.

Since most platforms are leaky, one ends up needing to master two ecosystem in parallel, eventually it gets tiring and always cost extra in development.

C++, Objective-C and Typescript get around this problem in UNIX and Web, as they are extensions of the platform languages, not something completely different.


Yep agree with all you said. Nowadays new job every year people at work are scaring me with their enthusiasm to replace decades old solid Java applications which are performant and working fine with Kotlin and what not.


I wouldn't advocate for replacing/re-writing old stuff - but you should try out Kotlin for backend work. It's amazing.

Java programmers will have only a small learning curve before feeling productive, and can gradually get more comfortable with idomatic Kotlin as they progress through their journey.

Kotlin, as a language, was very well through out, letting you use as much or as little of it as you are comfortable with.


For me personally Kotlin does not bring that much to the table over a modern version of Java. Sure if you're stuck in Java 8 it can be a win, but compared to Java 21 it just doesn't bring enough to warrant the switch for me.


Honestly the main thing I find killer about Kotlin over Java is its stricter null safety (types do not permit null values unless you mark the type as nullable with a "?" suffix). (I know Java does have the @Nonnull annotation but it's extremely verbose to use much and Java doesn't enforce its use on values that are expected to be non-null, which both greatly diminish its usefulness.) I've been spoiled by languages like Typescript and Rust which have great null safety like Kotlin, and it's very annoying going back to a language without it and questioning whether a null is expected or possible for every single value.


I wish I could get a strong sense of the hype around null safety. Sure, I would like to have the extra expressive option. However, optional has been fine for me. I still barely use it. It has to be at least 3-4 years since I last encountered a null pointer exception in my daily java programming. I feel like there are plenty of other things that pain me on a daily basis that rank far higher on my asks for the language. Collection and stream ergonomics cause constant pain, for example.


Infinitely chainable expressions, .let, .also and friends. You shouldn't overdo it (lengthwise) and it's almost hilariously superficial, but I miss it in every other language since.

Tying down a value to a name only if you have something meaningful to say in the name, and only when the value is actually finished instead of being a work in progress, that gives me great piece of mind and frees up mental resources for other things. I wish every language had a "kotlinized" sibling that simply added the scope functions on syntax level (or a subset of the scope functions, not sure you need a zoo that size)


I personally find let, also, and friends to be a clarity nightmare. For me, they make reading code harder.


It's not always better, I give you that. If something does not work as expected you might even find me transforming code to conventional imperative style. But I feel like I have a much better shot at getting it right in the expression chain style, and in all styles if scopes are not polluted by dubious intermediaries and/or badly named one-callsite functions thanks to letisms. By the time the "let tax" grows too high, chances are that the block in question is big enough to make the "factored into a function tax" bearable.


I’ve seen this sentiment a lot and I don’t understand it. I actually feel like very little has been added between Java 8 and Java 21. Virtual threads is probably the biggest thing, and it looks very promising, but the language itself is still a chore to use, and Kotlin does a good job at cleaning a lot of that up.

I think Kotlin is at risk, though, of having the JVM force them to support two competing models to accomplish the same thing - coroutines and virtual threads is a good example (although Java still doesn’t have language level structured concurrency). This could really make things messy.


> I’ve seen this sentiment a lot and I don’t understand it.

I just don't think any feature of the language of Kotlin is that much better than Java's implementation. I'm also a big supporter of brevity != clarity when it comes to code.

What language feature in Kotlin do you think is that much better?


I was you not that long ago. I've had the same conversation with a lot of other Java developers too - they/we always say the same things.

It's weird being on the other side of the fence now - hearing the same things I used to say.

Kotlin was a gateway drug out of not just Java, but OO/Solid and into FP for me (FP being another thing I used to not "get"). The beauty of Kotlin is you don't have to ever write FP code if you don't want to - but you will want to before too long.

I would recommend trying it out for yourself. It's Spring integration is amazing, and you'll have a great time. Write even a little Kotlin and you'll have an "ah ha!" moment and everything will forever be different.

It's one of those things where you need to experience it for yourself before you actually understand how great it is. There is no argument you will hear that will convince you, sadly. I was the same once...


To me Kotlin is different enough to be annoying to learn, but not different enough to matter that I use it over Java. So it just kinda feels like a waste of time.


You can do many FP things in Java as well, as it is a multi-paradigm language, hell, Kotlin is not even particularly functional-y.


I'll agree that Kotlin is not hardcore FP (although you can get there some of the way with Arrow etc.), but FP in Java is clunky.

- Having to remember the difference between "Function", "Consumer", "Predicate" and "Supplier" is weird. In Kotlin (and basically every other typed FP language that I know), I just write the type signature the natural way.

- Having to use streams in order to use map, etc., is noisy. Why weren't these APIs retrofitted to collections?

- Checked exceptions are a pain with functional code, e.g. map.

- Mutability is still the default behaviour of almost everything in Java, save records (and strings).

etc.


> Having to use streams in order to use map, etc., is noisy. Why weren't these APIs retrofitted to collections?

Sure, methods along the lines of the following could have been added:

  public <R> List<R> map(Function<? super E, ? extends R> mapper) {
      return stream().map(mapper).toList();
  }
Yes, having them would make Java less verbose in the case where you only want to do a single map, filter, whatever operation on a collection, but I'm personally glad that they weren't because they produce extremely inefficient behavior when chained. So, it would add a performance footgun to save ~18 characters.


But are these things enough to warrant me a full switch of programming language and ecosystem? Not for me.

- I don’t think this is really that big of a deal.

- Using streams is actually preferred so you don’t cause a performance nightmare and kotlin you has to use asSequence anyway.

- I thought checked error handling was all the rage nowadays?

- Mutability is absolutely fine if you’re not going over a thread boundary.


In Kotlin, asSequence gives you lazy behaviour (i.e. chains of map, filter, etc. are merged the way it's automatically done in Haskell), but if you don't care about the performance penalty, you can just call map, filter etc. on eager collections too. I'm of the opinion that you shouldn't prematurely optimise, for small enough data, it often doesn't matter much.

And checked exceptions are widely seen as an anti-feature - I don't think any other language has them, with the possible exception of Swift (see below), and for good reason. Other languages encode errors (more or less ergonomically) in the type system (e.g. Rust, Haskell, and to an extent it's what Kotlin advocates as well), and that has the advantage of playing well together with other language mechanisms - e.g. no extra allowances need to be made so that map works with them.

But for the sake of the argument: Swift also has something similar to checked exceptions, but only in the sense that functions can either throw or not throw. However, Swift also at least has constructs like "rethrows", which lets you say that a function such as map should throw iff the higher order function it wraps throws.

Java simply decided that it doesn't need to deal with this problem at all (for whatever reason - they simply could have added something like "rethrows") and now it's up to callers to deal with the incredible awkwardness that is using FP with Java library code that makes heavy use of checked exceptions.


Null safety checks and if being an expression are major pain point resolvers that are still not available in Java (OK, maybe pattern matching helps the if-expression part, because pattern matching IS an expression in Java). Oh, and the legacy library APIs, which Kotlin elegantly wraps with FP-compatible classes. Instead of fiddling with streams (which also lack some basic operations, or have some not so nice API), you can just .map or .fold over your (read-only by default) collection. Not only less verbose, but also easier to use and understand. Having said this, these are fairly minor things, which may not warrant a switch to Kotlin, if you are otherwise happy with Java...


> I think Kotlin is at risk, though, of having the JVM force them to support two competing models to accomplish the same thing - coroutines and virtual threads is a good example

I don't think it's that good an example, though there's some merit to it. Kotlin coroutines, to me, target three main use cases:

1. An abstraction over an underlying threading model. Get threaded execution without having to explicitly deal with thread pools and such. I'd consider structured concurrency to be part of this use case.

2. A way to write non-blocking code that is structured as if it were blocking. (Incidentally: I love Kotlin's decision to make "await" opt-out instead of opt-in.)

3. A way to write code that generates sequences of values without having to either write an explicit class that maintains state across calls or use callbacks/CPS. Or in other words, a way to use the "yield" function.

Use case 1 still makes sense with virtual threads. Run your coroutines on an executor that uses a virtual thread pool instead of a platform thread pool. If you prefer the coroutines API, you can still use it for structured concurrency and such.

Use case 2 is much less interesting in the presence of virtual threads; you can just write blocking code directly, no need for the language to turn it into async code for you.

Use case 3 has nothing to do with threads to begin with, so it remains exactly as valuable as before and there's no reason to change any existing code at all.

Do coroutines get less useful in the presence of virtual threads? Absolutely. But they aren't competing with virtual threads; there are substantial non-overlapping use cases that make them a worthwhile language feature.


> I actually feel like very little has been added between Java 8 and Java 21.

var, records, sealed types, and pattern matching make a huge difference in how Java is written. A lot has changed since 8.


This is a pretty unimpressive list for 9 years of progress, and is merely a small subset of features Kotlin was already providing.

I left the Java world for the C# world around 2008 and then returned to the Java world last year. C#/.NET changed much more significantly much faster. Almost all of the significant differences in day to day life with respect to the Java language and standard libraries that occurred between 2008 and 2022 are due to changes introduced with Java 8.


The issue with these new structures is they're necessarily clunky, to maintain interoperability with non-modern Java. Java's backwards compatibility is legendary, but is also why some of it's newer features are often criticized as not being as good as they could be.


It's one thing to say, "very little has been added between Java 8 and Java 21," and something else entirely to say, "newer features are often criticized as not being as good as they could be [to maintain backwards compatibility]."


I don’t think any of then is clunky - hell, pattern matching is straight better in java.


Kotlin is the closest thing to a "better Java" that I've found. I've used it with Spring Boot and the interoperability with Java is fantastic. A Java dev would have no problem picking it up quickly (as opposed to Clojure and even Scala).

I say this as a Clojure fan, there are many instances where I'd probably choose Kotlin nowadays. You can also mix JVM languages within the same application; I've found it rather useful to sprinkle some Clojure into a Java/Spring application for certain tasks. Maven and Gradle both have tooling to handle it :)


If you're into FP stuff, using Arrow within Kotlin takes you to that next level. It even works with Spring/Boot.


Couldn't agree more! It's particularly disappointing when you need to work on an older java codebase after finishing a Kotlin project. You'll constantly miss features


> You'll constantly miss features

Like what?


Nullable types, module level functions, context receivers, nicer type signatures for functions, a better standard library (e.g map works directly on lists without the stream.map crap)


Personally, these features are not something I feel like I would constantly be missing. I don't constantly feel like I'm missing them after switching from JavaScript, at least for not having to call .stream(), context receivers (which Java provides with ScopedValue), or signatures for functions.

I'll give you nullable types, though I personally don't struggle with null at all.


Even C# seems like something stuck in the 1990s compared to Kotlin. (I know it’s not a high bar).


Not kept up with the times in regards to C# 12 features?


C#'s problem is it's quickly becoming C++ in that it doesn't just have the kitchen sink, it has three kitchen sinks...

Unlike C++ though, one day the powers that be will just remove features as part of yet-another framework rewrite and you'll just have to deal with it.

The other issue is just how tightly coupled C# as a language is to the .NET framework/platform. Some of the things people like C# for are actually framework things and they don't realize it because that separation isn't as clear as with Java and say, JavaEE or Spring or $X.

If you talk to a C# developer - of course they're using .NET and of course they're using Entity Framework - to them, there's no other way. It's inconceivable that any other library or framework might do it better than Microsoft's official offering... and then you'll find the official offering to be lacking in fundamental ways.

Talk with a Java developer and you'll find there's a lot more diversity of frameworks and libraries being used - so there's a lot more differing opinions on priorities and a lot more good ideas being tried out or implemented everywhere. The communities are vastly different in that regard.


Collection literals are going to be fantastic. Many don't know that there is actually momentum to keep moving right into Dictionary literals.

There is a "roles" proposal and investigation team. This roles proposal is going to unlock so much potential it is bonkers.


Collection literals are a pointless extension of the pattern matching syntax added to get around the fact that there is no way to name a generic type in C# without specifying its type arguments.

It's yet another double down on object initializers instead of writing constructors and factories, and unlike using a factory you have to fully express the result type of the collection instead of having it inferred (they are "target typed", another feature that probably should not have been added).


There is a pattern matching aspect but I think the energy behind it is largely motivated by a desire to clean up syntax when working with data structure based APIs and DSLs.

I've read the proposal, design meeting notes, and GH conversations. Not seeing a compelling counter argument here.


What do you think I’m missing that makes C# 12 not a-lot-of-lipstick-on-a-java-pig?


It is still another syntax, with idioms moving away from JVM, their own little islands of Kontlin only libraries, and only works on InteliJ/Android Studio.

I don't see any value in Kotlin outside Android shops.


While true it has it's own syntax, the syntax is better than Java and more ergonomic. With that said, you can write Java in Kotlin - and by that I mean Kotlin code that looks almost exactly like Java. Heck, you can have .java and .kt source within the same project all mixed together if you want.

Kotlin libraries are interoperable with Java and vice versa. In some specific cases, a Kotlin library needs a little syntactic sugar to make it work with Java like a Java developer would expect, but it's easy to do. Going the other direction though - Java library used in Kotlin, zero issues, it just works. Some Java developers don't even realize they're already using Kotlin - take a look at OKHttp and friends...

Lastly, there's Kotlin support is all major IDE's, including IntelliJ of course, but also Eclipse and likely whatever editor/ide you prefer. Kotlin is basically just a bunch of libs.

I would argue Kotlin is better outside of Android than in Android. For backend work, particularly when coupled with Spring/Boot, it's freaking amazing. The Spring team has put in an impressive amount of work to make Kotlin a first-class language within the ecosystem, and it really shows.


Try to call Kotlin co-routines from Java.

Telling me there is Kotlin support in Eclipse only tells me you never actually tried it, specially after JetBrains ramped down the team that was doing the now stale plugin.


You should look harder before saying it doesn't work. Updated 10/6/2023[1]

Coroutines are a specific paradigm within Kotlin, and should not be in library code anyway. With the addition of JVM Virtual Threads, the need for Coroutines is significantly diminished anyway.

It's anecdata, yes, but I've written a lot of Kotlin code and do not use coroutines. Kotlin really just lets you do what you want - as much or as little idomatic code as you need.

Kotlin on the backend is amazing. You really should give it a try. Java sucks badly, in comparison (I say that as a former Java nerd...)

[1] https://marketplace.eclipse.org/content/kotlin-plugin-eclips...


And you should read before posting random links,

   After installation of the Kotlin plugin the Java plugin is not running anymore. I cannot open a Java project anymore.

   The log file says:

   !MESSAGE org/eclipse/jdt/internal/ui/refactoring/actions/RenameJavaElementAction$AjcClosure1
   !STACK 0
   java.lang.NoClassDefFoundError: org/eclipse/jdt/internal/ui/refactoring/actions/RenameJavaElementAction$AjcClosure1
    at org.eclipse.jdt.ui.actions.RenameAction.<init>(RenameAction.java:60)
    at org.eclipse.jdt.ui.actions.RefactorActionGroup.<init>(RefactorActionGroup.java:372)
    at org.eclipse.jdt.ui.actions.RefactorActionGroup.<init>(RefactorActionGroup.java:206)
    at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.<init>(PackageExplorerActionGroup.java:139)
    at ...


You copy/pasted an error some random person on the internet had in June due to using an incompatible Eclipse & plugin versions?

The beauty of Eclipse is the ecosystem. If that official Jetbrains plugin doesn't do it for you for some reason, then use another one[1].

[1] https://marketplace.eclipse.org/content/enhanced-kotlin-ecli...


I've worked in several JVM backend projects, and Kotlin has been a stark improvement over Java (at least up through version 17, the most recent with which I've worked directly). Compose, and Compose UI, are tremendously promising technologies; I've shipped desktop apps with Kotlin for multiple platforms, and compared to just about every other desktop UI framework, it's a clear winner in terms of productivity and an ability to GSD.

All that to say, I believe that Kotlin has a lot of value, independently of Android.


> I don't see any value in Kotlin outside Android shops.

Developer experience is important to some people - not just devs, but those who seek to recruit and retain good ones.

Of course, if you're looking to hire massive numbers of butts-in-seats (gov work, large enterprise shops, etc) I suppose Java is probably the ideal choice.


"Only works on IntelliJ" is patently false. Stop spreading FUD.


Where is Kotlin support for Eclipse and Netbeans?

Prove me wrong.


Do you use Eclipse? Have you looked at the available plugins?

There's nothing special about Kotlin. It's a bunch of libraries for runtime and compile time... like anything else you use.


It is my main Java IDE.

There is a difference between supporting a language with a Notepad++ like experience, and what JetBrains was doing before ramping down the Eclipse plugin team, as means to sell more InteliJ licenses instead.


What do you believe you are missing?

It compiles fine with Maven or Gradle, it provides auto-prompt/complete/hints. It just works.


Same experience as in InteliJ, which JetBrains no longer provides.

And above all, no crashes left and right.


I'll ask again more clearly - what is the "same experience" you are missing?

Kotlin is plugins for Maven/Gradle, and classpath libraries. There is no magic going on here...


I did a year of Kotlin in a recent job. I liked it, but not enough to prefer it over Java - especially with the recent updates to Java. YMMV


That would only be a bad thing if the Java ecosystem was good to begin with.

From my perspective it is terrible enough that the language specific wrapper library has 10x to 100x the usability of the Java option if you use it directly from Java. For example, GORM for Groovy is significantly better than Hibernate even though it is built on top of Hibernate. It is so good that I chose to use groovy once, not because it made sense but simply because Hibernate is so terrible, the cost of a different language was outweighed by it.

I don't give a damn about most JVM features. They don't change the crap ecosystem at all. I personally despise the JVM for being incredibly memory inefficient as well. None of this is going to change.


That's an interesting hypothesis. Is that applicable to platforms other than programming languages?


And many developers are tired of Java making minuscule improvements to developer ergonomics while pretending to be progressing, when even now, it doesn't have features that other languages have had for 30 years.


Based on pure statists about the number of important, business critical java-applications that run most of the internet, it seems like it just straight doesn’t matter in any significant way.


Maybe it doesn't matter to you, but it does matter to me.

All the power to people who enjoy working in Java, but that doesn't have to make me like it.


The JVM and Java the language have always been intertwined. The same people that develop the language, develop the VM. Lots of optimizations in the VM know specifically about Java the language idioms and implementation details. Check out this function which helps determine if instance fields are trusted: https://github.com/openjdk/jdk/blob/edd454b502b9bacde5549282...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: