News for hackers. Stuff that matters.
Re:Java Is in Decline, and There's Data to Prove It by pulse7 on Sunday January 01, 2023 @09:01AM (#34206289)
Kotlin may be growing on GitHub, BUT Java has the "late-mover advantage": it will incorporate all good ideas from Kotlin & others into the language and it will skip on all failed ideas (like async/await, etc.). So the Kotlin advantage is shrinking - just like it happened with Groovy and others. The Java ecosystem is huge - you have libraries for just anything. And it is similar to Raspberry Pi vs other competitors: RPI has ecosystem, others are much smaller.
Re:Java Is in Decline, and There's Data to Prove It by kmac_ on Sunday January 01, 2023 @09:28AM (#34206490)
Async/await with futures/tasks/promises is really useful. Having async build in a language simplifies code and reduces boilerplate. Of course it introduces function "colors" as some say, but that's a good tradeoff imo as it's easy to handle (much easier than not having async/awiat). Java ecosystem is quite behind and won't catch-up because the language itself has some pain points like type erasure, nullable references (even C# got rid of that), etc. and that won't change ever. The most popular libraries and frameworks are stuck in time. Languages are moving forward and developers follow that, Rust, TypeScript show the way.
Re:Java Is in Decline, and There's Data to Prove It by Reason077 on Sunday January 01, 2023 @10:01AM (#34206752)
> "The most popular libraries and frameworks are stuck in time."

When you're building software with a design lifespan of decades or more, this stability is advantagous. You don't want to have to go back and make big code changes (ie: pay increased maintanance costs) every few years because the libraries and frameworks you used are moving targets.

Re:Java Is in Decline, and There's Data to Prove It by blagie on Sunday January 01, 2023 @10:44AM (#34207201)
I like async/await, but I haven't seen any language do it well. Doing it well would involve:

1) Not crashing-and-burning on simple "Hello World" level use-cases (e.g. working in a Python terminal, a 3-liner script, etc.)

2) Giving actual performance gains in typical cases

3) Allowing code to change in both directions, quickly and easily

4) Integrate well into other parts of the language (e.g. list comprehensions or iterators / generators in Python, or multiprocessing)

I also don't like the amount of verbosity added. I can describe a system which would do all-of-the-above, but I don't think I could have independently invented it. It's based on using JS and Python async / await for a while, and understanding where things were done wrong.

On a mile-high level, I'm also ultimately not sure this is the right model. We:

- Created cooperative multitasking (e.g. in Windows 3.1 and earlies)

- Found pre-emptive multitasking worked better, in part since people were bad at deciding when to release control

- Re-invented cooperative multitasking within apps with async / await

I think there is a more dynamic, higher-level programming model where I describe what needs to be done. Just-in-time profiling and optimization, decides what to do synchronously versus asynchronously versus in a new process versus e.g. on a GPU. An operation like:

    [functional_function(x) for x in l]
Ought to sit on CPU synchronously if l is small and f is fast, in their own process asynchronously if they are medium, and on a GPU if they are massive and slow.
Re:Java Is in Decline, and There's Data to Prove It by kasperni on Sunday January 01, 2023 @11:09AM (#34207445)
> won't catch-up because the language itself has some pain points like type erasure, nullable references (even C# got rid of that), etc. and that won't change ever.

I wouldn't be so sure if I was you. A lot of work is being put into JSpecify [1] lead by Google and with most major players in the Java ecosystem participating. If it is a success we might see it in the language one day and not just with annotations.

[1] https://jspecify.dev/

Re:Java Is in Decline, and There's Data to Prove It by oweiler on Sunday January 01, 2023 @11:56AM (#34208023)
At some point Java will introduce value types, which are non-nullable.
Re:Java Is in Decline, and There's Data to Prove It by invalidname on Sunday January 01, 2023 @01:45PM (#34209318)
I assume the parent is referring to Loom which makes synchronous threading as efficient for throughput as asynchronous. This has multiple advantages such as a simpler model, easier debugging, understandable stack traces, etc. This is better and simpler than async/await.
Re:Java Is in Decline, and There's Data to Prove It by PaulHoule on Sunday January 01, 2023 @01:50PM (#34209382)
Sometimes I wish I had more colors to put on functions to organize my program, storage, resources, etc.
Re:Java Is in Decline, and There's Data to Prove It by joe_fishfish on Sunday January 01, 2023 @09:28AM (#34206486)
I believe there are no plans to port Kotlin’s null safety to Java, which is possibly the biggest advantage Kotlin has right now. Once you’ve tried it there is no way you would want to live without it.
Re:Java Is in Decline, and There's Data to Prove It by pulse7 on Sunday January 01, 2023 @11:14AM (#34207517)
If this is the "biggest advantage Kotlin has right now" then it doesn't have much added value... Would you rewrite existing code base with millions of lines of code just to get null safety? If THIS is the biggest advantage of Kotlin, then Kotlin is on the same path as Groovy was a decade ago...

In order to replace Java and it's ecosystem one would need to offer MUCH MORE than just null safety...

Re:Java Is in Decline, and There's Data to Prove It by joe_fishfish on Sunday January 01, 2023 @06:04PM (#34212049)
It would depend on the state of that codebase, really. If it’s well tested and does its job well, I wouldn’t bother rewriting it at all.

But certainly if I were to add new features to an existing Java codebase I’d use Kotlin. The interop between the two is fantastic and for me the null safety alone makes it worthwhile.

Re:Java Is in Decline, and There's Data to Prove It by bennysonething on Sunday January 01, 2023 @09:08AM (#34206341)
I primarily write c# for a living. What's wrong with async await in kotlin? I'd struggle to live without it in c#.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @09:13AM (#34206378)
Async/await is extra syntax and one more function color which you have to keep in mind, while being just a workaround for expensive threads.

Recent Java has just made threads cheap, so async concurrency is much simpler and more consistent with existing libraries and APIs.

Re:Java Is in Decline, and There's Data to Prove It by joe_fishfish on Sunday January 01, 2023 @09:34AM (#34206535)
Cheap threads are fine if you’re in a server environment, and you need to spin up a large number of short lived parallel jobs.

It’s not hugely helpful for a UI-bound application which occasionally needs to move some work into a background thread to cut down on UI jank.

Kotlin’s suspending function syntax effectively lets you know which operations are going to (potentially) take a while, so you can make sure the UI thread isn’t blocked, and also make sure you’re communicating to the user that something is happening.

Re:Java Is in Decline, and There's Data to Prove It by kasperni on Sunday January 01, 2023 @11:12AM (#34207493)
Custom schedulers are coming later with Project Loom. Should be fairly easy to create something where particular threads could have a higher/lower priority.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @01:10PM (#34208903)
If I understand your point correctly, you say that suspend keyword gives you a hint for which functions are long running, so that you run them in a background thread.

I think that’s a very flawed assumption. Some IO operations are pretty fast, like reading a local filesystem, and can be done in the UI thread, while some heavy non-async functions are accidentally O(n^2), and freeze your IO thread.

And if you say that “of course you should know what you’re doing”, then I think that suspend syntax just adds extra complexity without much semantic benefit.

Re:Java Is in Decline, and There's Data to Prove It by invalidname on Sunday January 01, 2023 @01:47PM (#34209338)
Loom has zero impact on client, sure. But I disagree that async is better for client. It makes it much harder to debug and track issues.
Re:Java Is in Decline, and There's Data to Prove It by pharmakom on Sunday January 01, 2023 @09:23AM (#34206456)
An Async<T> is not a T whether you have the monadic sugar or not.

Why make life more difficult when you can have code that reads linearly?

Re:Java Is in Decline, and There's Data to Prove It by wiseowise on Monday January 02, 2023 @09:08AM (#34217945)
In Kotlin it is just T, the function is suspend.
Re:Java Is in Decline, and There's Data to Prove It by pharmakom on Monday January 02, 2023 @11:06AM (#34219442)
Then the language is implicitly converting it through suspension for you. They are still different things. What if you don’t want that to happen?
Re:Java Is in Decline, and There's Data to Prove It by tluyben2 on Sunday January 01, 2023 @09:43AM (#34206599)
Can you provide a good cheap thread example for Java vs async/await. What I find online is horrible compared to async/await but people keep talking about function colouring etc. I just cannot see what is the issue. Nor do people give better examples; I was watching some guy on YouTube who said async/await sucks and my idea is better, then spent 30 minutes explaining his idea vaguely. No implementation, no examples.
Re:Java Is in Decline, and There's Data to Prove It by nlitened on Sunday January 01, 2023 @12:50PM (#34208692)
In the simplest case, you take an async function, remove `async` and `await` keywords, and as a result you get a normal function which you can call and get a result without awaiting, which has better and more predictable performance, and a straightforward stack trace (and a simpler language syntax and semantics). All upsides, no downsides.

Probably you can think of a more complex example where it’s not that straightforward, please link code that you have in mind, we can see how with cheap threads it could be made better.

Re:Java Is in Decline, and There's Data to Prove It by pulse7 on Sunday January 01, 2023 @09:09AM (#34206349)
Function coloring
Re:Java Is in Decline, and There's Data to Prove It by andix on Sunday January 01, 2023 @09:17AM (#34206399)
Async/await doesn’t change anything there. It just makes it easier to deal with.
Re:Java Is in Decline, and There's Data to Prove It by justoreply on Sunday January 01, 2023 @10:34AM (#34207088)
With the new thread model in java (project Loom) you don't need function coloring
Re:Java Is in Decline, and There's Data to Prove It by andix on Monday January 02, 2023 @10:04AM (#34218608)
I don't know the details. But a synchronous function returns a value and an async function returns something promise-like (it completes at some point and returns a value or an error).

You can always call something async synchronously (by waiting for finishing). Or something synchronous in an async way (by putting it onto another thread). But there is no way to completely remove this fact from the eyes of the programmer. async/await is one of the ways to make it easier to read or write.

Re:Java Is in Decline, and There's Data to Prove It by sshine on Sunday January 01, 2023 @09:04AM (#34206321)
Java has historically been good at catching up when competing languages outran it.

C# was a better language than Java for some years until Java caught up again.

Re:Java Is in Decline, and There's Data to Prove It by jen20 on Sunday January 01, 2023 @09:09AM (#34206355)
C# is still a better language than Java, despite the purported catching up.
Re:Java Is in Decline, and There's Data to Prove It by neuronic on Sunday January 01, 2023 @09:20AM (#34206428)
Can you describe the fundamental advantages of C# over Java?
Re:Java Is in Decline, and There's Data to Prove It by tester756 on Sunday January 01, 2023 @12:43PM (#34208612)
LINQ, properties, maybe reified generics, less annotation-oriented programming
Re:Java Is in Decline, and There's Data to Prove It by cumironin on Sunday January 01, 2023 @10:50PM (#34214081)
annotation is love, why people hate it ?
Re:Java Is in Decline, and There's Data to Prove It by tester756 on Monday January 02, 2023 @05:43AM (#34216481)
magic + mehh debugging
Re:Java Is in Decline, and There's Data to Prove It by yen223 on Sunday January 01, 2023 @09:04AM (#34206319)
Can Java steal top-level functions already?
Re:Java Is in Decline, and There's Data to Prove It by pulse7 on Sunday January 01, 2023 @09:08AM (#34206342)
Just use static methods for that. Disadvantage: you are forced to use package and class name spaces. Advantage: everything is inside some namespace.
Re:Java Is in Decline, and There's Data to Prove It by jrpelkonen on Sunday January 01, 2023 @12:36PM (#34208537)
Agreed. I also find static imports handy to simplify the code at the call site.