Hacker News new | ask | show | jobs
by nunobrito 285 days ago
Programming language is a tool. Java developers value stability and ease of understanding for the code. I've seen the nice features you complain that don't get used, reality is that nobody wants to waste time knowing them unless they are intuitive to use. Especially when are forcing to use newer JDKs.

There is no value in solving a challenge in a way that only you understand or make others lose time trying to understand the logic.

Java 8 was the peak of development age for the JDK. Everything that came after isn't really memorable nor helpful, especially lambdas. You mention "var", why would we ever want in Java to hold a variable that you can't read immediately what is the type? That is a source of bugs and time waste to track down what object is being used.

I don't mind you are happy with all these changes, just remember that we absolutely don't care about them nor will make much of an effort because in the end of the day we don't want to follow the same route of other programming languages unable to handle gigantic and complex platform systems.

This isn't a competition to showoff who can apply new tricks, we absolutely don't care about functional programming. Java code must be simple and easy for anyone to read, that's it.

8 comments

The new features make the code easier to read. For example var:

    List<Account> accounts = List.of(new Account(1), new Account(2));
    var accounts = List.of(new Account(1), new Account(2));
It just reduces visual noise and boilerplate that you already know.

Java 8 is also a slow and old runtime. It performs terribly in 2025. Here’s a quote from 2020 and the gap has only gotten wider [0]:

> JDK 8 is an antiquated runtime. The default Parallel collector enters huge Full GC pauses and the G1, although having less frequent Full GCs, is stuck in an old version that uses just one thread to perform it, resulting in even longer pauses. Even on a moderate heap of 12 GB, the pauses were exceeding 20 seconds for Parallel and a full minute for G1. The ConcurrentMarkSweep collector is strictly worse than G1 in all scenarios, and its failure mode are multi-minute Full GC pauses.

You’re doing a disservice to everyone by continuing to use and glorify it.

[0] https://hazelcast.com/blog/performance-of-modern-java-on-dat...

Using Java 8 doesn't mean using the java 8 JDK. It just means not using the newer features. I don't see anything in the parents post about restricting which JDK they use.
> Java 8 was the peak of development age for the JDK.

Still glorifying it.

There is about zero difference in readability of your two statements, rending var not useful.

And 'var accounts = calculateAccounts(something)' is literally less readable, because now you dont see what exactly accounts is.

Var statement speed up writing, then are either irrelevant or gets rewritten to types for better readability.

the advantage of var is not clear in toy examples. in real life, people write stuff like

  Map<String, MyExtremelySpecificAndVeryLongTypeName> myExtremelySpecificAndVeryLongTypeNameMap = myExtremelySpecificAndVeryLongTypeNameMapProvider.provide();
literally anything to reduce the number of line breaks needed for a single statement is welcome.
I agree, and I'm not sure how something like 'var accounts = calculateAccounts(something)' can be thought of as better in a code review setting. I suspect using "var" or equivalent will be considered a problem by most companies within the next few years.
This experiment has already been run with pretty much every language that isn’t Java or C, and I think most people have been ok.

Yes, code review is arguably worse, but most people who write Java do so with an IDE and the type is never unknown at that point.

Also, if your function is big enough to where the type of var is not very clear, it likely shouldn’t be passing code review regardless.

Those writing in python and javascript don't honestly know any better. They grew in a world without unit testing or without products that need to grow into gigantic systems maintained over the next decades.

This reminds me of a developer writing in jRuby because "it was better". While he was in the company he'd still give support to his own works, after leaving nobody else wanted to pickup those "better" things and would prefer to write workarounds to the tool, it effectively became a black box that few could improve and even worse to test. As result, those portions had to be rewritten in proper Java so that we'd be able to deeply measure/test and improve.

Never again.

There’s nuance in programming. Both of these statements can be true. Var reduces boiler plate when you’re duplicating information in both the lvalue and rvalue.

I’m in agreement that when the information isn’t in the rvalue that you shouldn’t use var.

Var can help in maintenance. Change the return type of calculateAccounts and you don't have to modify this code (assuming that it duck-types out equivalently).

That isn't necessarily a huge win: it does force a compile change that isn't obvious from the source. And a refactoring tool could have performed the code change automatically so it's not as big a deal as it might have been.

I would argue that it helps me when performing maintenance to see and correct where types may have changed. Not always, and sometimes it is busy work I agree, but overall I prefer it.
Yeah I generally avoid using 'var' to elide method return types for that reason. In my early phase of var enthusiasm I even had it result in a bug that would have been caught if the type had been made explicit.

I do still really like it in the `var list = new ArrayList<String>()` case though.

Modify it when? If the interface renames? IDE does that. If the actual return type changes? They you do have to check that place whether it is still valid.

Maintenance involves a lot of reading of unknown code. That is literally the situation where you are rewiting var to specific types to figure out what is going on.

I tend to agree here, I prefer explicitness. Even though yes it does mean some pain when refactoring, it also creates very clear diffs showing impact, which I consider a positive.

Ideally this could all be dealt with via tools. An IDE that shows whatever the user prefers, but is actually saving into a format defined for the repo.

It is less readable because either accounts is named incorrectly or calculateAccounts is.

If it should be createAccounts, nothing is lost unless you have multiple account types in which case you would call it createUserAccounts, create adminAccounts etc.

> is literally less readable

Please point me to an objective measure of "readability" that holds for all people. And then demonstrate that your example is "literally" lower on that scale.

Readability was a term coined by people writing languages that are litterally unusable without an IDE to hide stuff when they render the source file to explain why refusing to learn languages with curly braces is sane.
Oh man.. that comment really hit deep. I'll never understand why people argue that it is "easier" to adopt invisible characters and exact tab positioning instead of just using braces or similar to mark the code blocks.

Drives me nuts because you really can only write code for those programs with an IDE that is prepared for the case. Try to edit the code directly from the github web interface and it won't compile.

Whoops, my initial intent was "without curly braces", since that's where most of the readability comments are from. I guess the comment works both ways, though.

> Drives me nuts because you really can only write code for those programs with an IDE that is prepared for the case.

Usually people have strict rules for that (e.g. pep8), and most text editors will do it for you with little configuration.

> var accounts = calculateAccounts(something)'

Where did I write this? It’s almost as if there’s nuance in programming.

Var helps when you’re duplicating information that is already known. Your example is clearly not that.

> You mention "var", why would we ever want in Java to hold a variable that you can't read immediately what is the type?

var items = new HashMap();

Instead of

HashMap items = new HashMap();

That's the point of var. It reduces noise a lot in some situations.

You should write

    Map<String, Integer> items = new HashMap<>();
It allows you to limit `items` usage to `Map` supertype and allows you to swap implementation easily, if necessary. `var` is weird feature, because it allows people to use implementation-specific methods methods and tie code to a single implementation, essentially making it less agile.

There are valid use-cases for `var`, but IMO this feature should not have been added to the language, as it's too dangerous and most people won't use it responsibly.

Your example isn’t good though; var is only for local variables, which should be perfectly allowed to use implementation-specific methods.

For argument types you don’t have var, so methods that take in a map can stay abstract and you can still pass in the implementation-specific version into those without casting it to the interface.

ETA:

I guess I am trying to say that if you want to be abstract, they should be at the argument or properties level. Local variables should be used locally. I agree that generally speaking you should try and prefer using Map for anything shared across different parts of code but I am not convinced it’s bad to have var be implementation-specific; if your method is big enough to where swapping out implementations like this will take a lot of time, your method is probably too big anyway.

No, you shouldn't write that. Your variable should represent the complete implementation. Where you use it should be as generic as possible, for example, the parameter in a function call.
Why would you want that? The whole point of an interface or superclass is to let you swap implementations without changing everything.

I also like the nudge it gives you to use only the higher level methods, rather than the ones specific to the subclass unless they're needed. That also improves flexibility.

It’s not about swapping implementations, like the original poster suggested, so that you can later come in and swap out different implementations in a local sense. Interfaces are used to decouple parts of an application; for example mocking test interfaces. Another way to look at it is that interfaces are a contract that needs to be fulfilled.

Declaring a local variable as an interface to hide functionality so you can swap out functionality later is misunderstanding the fundamental theories around interfaces. Your variable should be whatever the function or method returns. If you want to abstract the type so it can be swapped out, create a function that returns an abstract type. Don’t tell the HashMap constructor it did the wrong thing. Now that I think about it, I’d recommend you use “var” in all cases, and not try to redefine the return values from a function.

While I do use `var` when appropriate, your example is in general not appropriate

You would like to use Map<Key, Value> items = new HashMap<>() since in general you do not want implementation detail leaking into contracts

Using var there doesn’t leak any implementation details into any contracts. Var is for local variables inside of functions. There are no details or contracts there.
> why would we ever want in Java to hold a variable that you can't read immediately what is the type

I can use my IDE to see the type if necessary.

> Everything that came after isn't really memorable nor helpful,

There are several improvements that are very helpful

One example is how multi line strings help me to read more clearly without the unnecessary string concatenations:

   var sql = """
             SELECT foo
             FROM bar
             WHERE last_updated > :lastUpdated
             """;
Another example is how switch statements have improved code readability, at least from my personal subjective viewpoint.

   String dayName = switch (day) {
      case 1 -> "Monday";
      case 2 -> "Tuesday";
      case 3, 4, 5 -> "Other day";
      default -> "Weekend";
   };
You could have as easily used String instead of var and there would be no ambiguity. This gets worse for numbers where it is important to know if you are dealing with an integer, long or something even bigger.

I agree with you on switches and do like the """ feature, thought. It was a real pain in the rear to include the multiple + "\n" back in the old days. This is a very clean and intuitive improvement.

> You mention "var", why would we ever want in Java to hold a variable that you can't read immediately what is the type?

I've been a full time java developer for the past 7 years. Let me start by agreeing that I have very little interests in the functional "innovations" they added. They're fine, but most of my colleagues agree that code using streams or lambdas very quickly becomes harder to debug then if you just wrote the code with loops and.

That's far from true for every java feature though. Switch statements have been super cool, Green threads are a promising road out of the CompletionStage hell the children are dreaming of these days. "var" is a very nice way to reduce double typing ("Thing x = new Thing()" -> "var x = new Thing()") and also a nice way to avoid changes to unrelated files ("Thing x = getFoo(); f(x);" -> "var x = getFoo(); f(x)" means changing the name of class Thing doesn't require any change to the code) that's been helpful in a lot of cases.

Yes, please don't get me wrong. There are always a few good things, but like you mention with streams: the person writing it can have an idea of what he was doing but the others afterwards will struggle to make changes and will likely revert the code base to simpler code.

Switch statements got better. I'm also getting used to Paths albeit don't yet understand why File wasn't already good enough. It is difficult to find compelling reasons for upgrading the JDK since I know it will be hassle for everyone that later down the line has to install/run the product.

If I had to guess, I'd say that a vastly bigger problem in the world is legacy code written in decades-old obsolete and inconvenient language dialects than code that's "too new".
I do not want to be rude but I am going to be: this entire comment illustrates my point very well. Instead of trying to actually learn new stuff, you say that the language peaked thirteen years ago.

> Everything that came after isn't really memorable nor helpful, especially lambdas.

Lambdas came out in Java 8, along with the streams API, and the fact that you don’t think they’re useful more demonstrates to me that you don’t actually understand it, since nearly every language before and after Java has lambdas and nearly everyone agrees that they’re useful.

Reifying a bunch of temporary interfaces is not “more readable” than a lambda. A bunch of terrible nested for-loop logic is not “more readable” than the streams API.

> You mention "var", why would we ever want in Java to hold a variable that you can't read immediately what is the type?

Your IDE can show the type, but even disregarding that there are lots of cases where you have to write the type twice in Java and it just makes noise. It doesn’t make the code more readable.

> we don't want to follow the same route of other programming languages unable to handle gigantic and complex platform systems.

Burying your head in the sand and Ignoring improvements in the language doesn’t make you more able to handle complex problems. It actually does the opposite and that’s so plainly obvious that I don’t think you actually thought through the sentence before you wrote it.

Take something like virtual threads. Most Java programmers don’t use them and instead keep using an executor service incorrectly because they also never learned the difference between blocking and non blocking IO. For them, virtual threads would be strictly better because it properly parks blocking IO.

Ultimately, I guess I disrespectfully disagree that Java “peaked” in 2012.

You know what's quite more important?

* Performant and safe standard library. * batteries included * a good way to actually care about managing dependencies, during build and runtime.

Okay, you got your stuff, please everyone now let's care about the standard library and that it really good.

> Especially when are forcing to use newer JDKs.

Dude, java 8's eol was 8 6 years ago, now. I have nothing gainst waiting a bit for "newer JDKs", but way too often the pattern is that teams use the oldest possible JDK and only migrate several months/years after the last possible vendor has sunset their support.

> Java 8 was the peak of development age for the JDK.

To me it looks it was merely the point where your stopped caring.