Live data from Hacker News

Java 21 makes me like Java again

wscp.dev

171–180 of 777 posts

Re: Java 21 makes me like Java again

#171
post #40

The problems with Java can't be fixed by adding new things, you can't undo decades of ecosystem development, training, and ideology built on top of the idea that inheritance is really good idea and belongs everywhere. edit: I will say that as a Java developer I am grateful every day for the improvements to the language. Java is a very impressive language and I have a lot of respect for the people working on it.

Please ELI5 what is wrong with inheritance and/or how Java have it wrong. Do we need to go back to a new object oriented undegraduate course? Genuinely asking.

Inheritance is fine. It helps to avoid code duplication for logic that requires encapsulated data (private, protected fields).

The problem is what if you have a class that needs to derive behavior that's in two (or more) classes? Multi-inheritance is terrible because it becomes a nightmare of which class overrides which.

If there's a shallow level of inheritance (1-2 levels deep), then there's nothing wrong with it. Things like composition for most use cases has been common advice since forever.

What happened with java was that there was a massive movement for enterprise code that way over-complicated everything based on ideas that didn't pan out. There were all these auxiliary patterns, and ideas that people had to learn to be onboarded onto projects, and so many people poorly understood them that it led to even more spaghetti code, too many people that developed using dogma instead of common sense.

Re: Java 21 makes me like Java again

#172

[flagged]

Do you feel good about yourself, talking down on people that made a perfectly valid choice by developing software in Java?

Let's look at the alternatives you mentioned: Rust and Golang. Java compared to Golang is a much more expressive language. Java compared to Rust is a much easier language because you have a garbage collector for the majority of the cases you don't need the manual memory controls that Rust offers you. In other words, Java is a perfectly valid alternative to both Golang and Rust with its own tradeoffs.

You try to paint a picture of Java not being cool but at the same time I see "modern" companies that are held in high esteem for their engineering prowess using Java to do incredible thing (e.g. Netflix and Google)

Re: Java 21 makes me like Java again

#173

Earlier quoted context omitted.

Throughput in Java can be quite high, and latency can be quite low. You still occasionally get latency spikes from the GC, but these days that's not so bad. (If you are extremely latency sensitive, stick to C++). Dependency injection frameworks are your bread-and-butter in server-side Java, and some can take a while to grok, but Java can be very productive after the chosen framework "clicks" for you. Typically, this…

> Java can be very productive after the chosen framework "clicks" for you. you can chose to not use DI frameworks at all..

DI buys you maintainability.

Without DI, there's too much flexibility in how objects get constructed. If you want to add new functionality to a legacy code base, it can be difficult to track down the different integration points and slow to plumb through your dependencies. These projects can turn into spaghetti very quickly.

DI solves this with a simple recipe: define your functionality, define your dependencies, wire it up to the injector.

The pattern is useful in all OO languages, Python and C++ included.

Re: Java 21 makes me like Java again

#174
post #50
post #19

Earlier quoted context omitted.

Depends- one of the hardest parts of the 11-20 upgrade for us was that cms gc was removed. If you run a bunch of different microservices with distinct allocation profiles, all with high allocation pressure and performance constraints, and you've accomplished this w/ the help of a very fine-tuned CMS setup, migrating that over to G1/ZGC is non-trivial

Java sort of suck for microservices (microservices suck on their own) as it has relatively high bootstrap cost. High allocation rate feels weird with micro services - I suppose that depends a lot on the coding style. G1GC is meant for generally large setups, with several cores at least. E.g. the default setup of 2048 areas on 2GB heap means, allocations over 1MB require special care.

If you GraalVM Native Image or one of the frameworks based on it then bootstrap cost disappears:

https://quarkus.io

Re: Java 21 makes me like Java again

#175
post #143

Earlier quoted context omitted.

And it is much more verbose, it is not even comparable in observability and on real world big applications (especially enterprise) you can't get away with value types and slowing down the threads to let the GC keep up with them -- Java definitely shines in these kind of conditions (GC-wise the only competition Java has is different Java GCs, really).

> you can't get away with value types and slowing down the threads to let the GC keep up with them I am not Go expert, but to me this is Go's big advantage: you can chose you want to have object GC controlled or be on stack and copied everywhere. GC controlled objects add lots of overhead, because malloc is expensive, and require lots of memory per object to track state and synchronize between thread, and that's why…

Sure, value types are a good thing, but they are no panacea in and of itself.

Also, any non-toy GC won't be using malloc, e.g. in Java's case allocating objects is barely more expensive than allocating them on the stack: they use a so-called thread-local allocation buffer, which can be used to allocate new objects in, without expensive synchronization, and the GC can quickly scan it, moving still alive objects out of it, and clearing the buffer.

Re: Java 21 makes me like Java again

#176
post #78
post #54

Earlier quoted context omitted.

Only if you're using vim like someone from the 70s, otherwise any sane IDE handles those things for you But, yes, namespaces are still mapped to paths, it's not like they rewrote the JVM to use blockchain or something

Yeah I really like my IDE doing stuff in the background without me knowing shit about it.

I don't understand how it is doing stuff in the background.

You literally ask it to move some class and then it does it. And it's very obvious what it's doing.

Re: Java 21 makes me like Java again

#177

[flagged]

I just picked up Java (via Kotlin) for the first time in four years, during which I've been doing Rails dev. I needed an AWS Lambda for zipping files into and out of S3. I banged my head against broken/unsuitable Node packages for doing so before finally giving up, since it is the lingua franca of Lambda. I was able to rewrite and deploy the function in Kotlin in two days' time. It was easy to set up and run, and wor…

AWS Lambda is the once place where you should never use Java. You have specific thresholds for how fast your function responds, jvm prevents that and requires more memory.

AWS Lambda’s documentation shows how to accept a Request and send a response. You don’t need a package for that. For making zips from s3, again, AWS’s sdk. It’s one of the most commonly asked questions on SO. Here’s one implementation for you that could have saved you days:

https://stackoverflow.com/questions/38633577/create-a-zip-fi...

Re: Java 21 makes me like Java again

#178
post #136
post #14

Earlier quoted context omitted.

None of the memory problems of C++, the speed of C++ most of the time. Thousands of high quality libraries, a JVM that is a marvel of engineering after 20 years, tooling for development, monitoring and introspection of exceptional quality. Many of the internal tools at the largest Cloud developed in Java. Most enterprise level software. NASA extensive use of Java. A team behind the development who has stunning common…

> None of the memory problems of C++ Every time I see something like this I roll my eyes... C++ doesn't have any "memory problems". There are sometimes human problems, such as thinking one is capable of coding without understanding the (basic programming) concept of a pointer. But that's because the human's dumb, not a language problem. (This argument also sometimes comes from those who do understand basic programmin…

I understand pointers, yet I can’t be trusted never to make a mistake with them. “Each mistake will go uncaught and become an unpredictable catastrophe” is a language problem when your target audience is made of meat.

Re: Java 21 makes me like Java again

#179

Earlier quoted context omitted.

> Java can be very productive after the chosen framework "clicks" for you. you can chose to not use DI frameworks at all..

DI buys you maintainability. Without DI, there's too much flexibility in how objects get constructed. If you want to add new functionality to a legacy code base, it can be difficult to track down the different integration points and slow to plumb through your dependencies. These projects can turn into spaghetti very quickly. DI solves this with a simple recipe: define your functionality, define your dependencies, wir…

the problem is that those DI frameworks are all adding substantial amount of complexity and brain load.

I started using just static factories in my code, and abandoned all those DI and it works well enough.

Re: Java 21 makes me like Java again

#180

The problem with Java is not Java. It is Oracle and no amount of new features is going to fix that.

I am wondering if Oracle is really playing significant role in Java evolution, they have some open process with many other companies contributing.

They are responsible for like 95+% of all OpenJDK commits.
Post reply on HN