Live data from Hacker News

Rating 26 years of Java changes

neilmadden.blog

271–280 of 327 posts

Re: Rating 26 years of Java changes

#271
post #50

I think the author is sleeping on Java assertions. I really like the feature, and it's really one of the features I feel Java got right. The syntax is very expressive, and they can easily be made to generate meaningful exceptions when they fail. It's also neat that it gives the language a canonical way of adding invariant checks that can be removed in production but run in tests or during testing or debugging (with -…

I'm quite surprised that he said asserts are not found in production code. Is that really so? I rarely write Java, but in C code we use asserts (in production code) all the time. It's not uncommon for functions to contain 2 or 3 asserts.

I think they're used less because the main reason for using them in C isn't a consideration in Java, and also they don't accomplish the same thing.

In C, asserts are used as sanity checks, and when one is violated, there's often reasonable suspicion that that memory corruption has occurred, or that memory corruption will occur if the code proceeds in the current state. Aborting the process, leaving a core dump for analysis, and starting fresh is often the safest thing to do to avoid the unpredictable results of corrupted state, which can be insidiously subtle or insanely dramatic. In my experience writing server-side C++, we always ran it in production with asserts enabled, because code that continued to run after memory was corrupted led to the the bugs that were the most destructive and the most mysterious.

Memory corruption is rare enough in Java that 99.9% of code completely ignores the possibility. Also, if you did suspect memory corruption in a Java program, an assert wouldn't help, because it would only throw a runtime exception that would probably get caught and logged somewhere, and the process would continue serving requests or whatever else it was doing.

Re: Rating 26 years of Java changes

#273

Earlier quoted context omitted.

> Why are you assuming you cannot write your own library and use it with Spring? I am not. I am literally saying the exact opposite.

Okay, that's fair. I don't even know anymore what point you are trying to make.

I was making exactly the point that you can use your own libraries along with a batteries included framework like Spring Boot.

I don't even understand what the source of confusion is. I literally said exactly the same thing in the comment you first you replied to.

Re: Rating 26 years of Java changes

#274
post #7

I'm sorry, please don't hate me (I'm tired and don't have anything better to do) https://files.catbox.moe/ge4el3.png

Why so much hate for modules? They seem to be almost universally disliked by everyone on this thread and I don't understand why.

They're fine, but they're incompatible with building fat-jars ro have single file deployment and dead to me because of that. Spring does some ugly jar-in-jar custom classloader stuff which I hate out of principle because it's spring.

Oracle hates that people build fat-jars and refuses to adress the huge benefit of single file deployables.

Re: Rating 26 years of Java changes

#275

Ah Java. The language I never got to love. I came of coding age during the “camps” era of object oriented stuff: Eiffel, Smalltalk, CLOS, C++, etc. Java, from 95ish to oh 98ish, was like a giant backdraft. Completely sucked the air out of the room for everything else. Does anyone remember the full page ads in WSJ for programming language, that no on quite yet knew what it really was? So my formative impressions of Ja…

For whatever reason, gpt-5 writes java code like it is 1995. I think it was trained on decompiled code.

Re: Rating 26 years of Java changes

#276

I don't know what to make of this list... Very strange reasoning and even stranger results: Streams 1/10?! Lambdas (maybe the biggest enhancement ever) a mere 4/10?! Sorry, but this is just bogus.

I'm that author. It has been more than a decade and still won't use streams nor lambdas. Makes the code too difficult to write and debug for me. Really prefer to have more lines of code and understanding very clearly what each one is doing, than convoluting too many instructions on a single line.

For me it's the opposite: If I had to write the code that I usually use lambdas for in any other way then _that_ would be very difficult to write and to debug.

Especially when writing JavaFX code which is full of callbacks and event handlers I really don't see any other (useful) option.

Can lambdas be misused? Of course they can - but so can every other code construct.

Re: Rating 26 years of Java changes

#278
post #170

Earlier quoted context omitted.

In theory, yes. In practice, I've found that things get really complicated as soon as you start trying to interact with the spring lifecycle. Figuring out how to customize things and manage priority is the trickiest thing in Spring, IMO.

Please use the facilities of the framework for debugging any lifecycle issues. I was surprised when I found out that people did not use `--debug` for example or enabled logging of application startup events. If you prefer GUI, Intellij even has a Spring Debugger: https://www.jetbrains.com/help/idea/spring-debugger.html

I stopped using Spring Debugger because for some inexplicable reason enabling it makes breaking at the breakpoint take minutes instead of seconds. For quite a while I didn't realize this was the problem, as IntelliJ started having it turned on by default at some point.

Re: Rating 26 years of Java changes

#279
post #196

Earlier quoted context omitted.

Checked exceptions are for errors that are not possible to prevent. How else should the caller know which exceptions are really likely to happen? Modules absolutely achieved their primary goal: stopping libraries from accessing JDK internals without the application's knowledge. The ecosystem is slow on the uptake since split packages and access to internal APIs is endemic, but it is happening ever so slowly. I wish l…

> Checked exceptions are for errors that are not possible to prevent. How else should the caller know which exceptions are really likely to happen? The same way, caller can know which exceptions are really likely to happen in TypeScript, C++, Python. Or in modern Java which avoids checked exceptions anyway. By reading documentation or source code. That's perfectly fine and works for everyone. And you highlighted one…

> The same way, caller can know which exceptions are really likely to happen in TypeScript, C++, Python. Or in modern Java which avoids checked exceptions anyway. By reading documentation or source code. That's perfectly fine and works for everyone.

This provides no automatic verification that indeed all likely error situation that can and should be handled were indeed handled. The very idea is that you have to opt in to not handle a checked exceptions. Result types don't carry a stack trace; apart from that I'm not convinced that they are interently better. In fact, I'd argue that handling a Result and an exception looks much the same in imperative code.

> When I'm writing reading data from resource stream, the data that's located next to my class files, IO Exceptions are really unlikely to happen.

Java class loaders can do anything including loading resources from the network. Which is admittedly not that common these days after the demise of applets.

> ByteArrayInputStream -> ByteArrayOutputStream

The general assumption behind IO interfaces is that the operations might fail. These two classes are oddballs in that sense. Note that the other write methods in `ByteArrayOutputStream` don't declare checked exceptions.

Since the compiler cannot prove that an exception will never be thrown (essentially due to Rice's theorem) there are always going to be false positives. The issues with checked exceptions therefore boil down to API design and API abuse.

Re Errors: the programmer cannot do anything about it and might make matters worse by trying to do so. Preventing an OutOfMemoryError relies on whole-system design so peak memory consumption is kept under control. Also the StackOverflowError, can in no way be prevented nor handled by the caller. Therefore both of them are `Error`s, not `Exception`s.

> NullPointerException probably happens more than any checked exception.

Patently untrue, as network connections break down and files cannot be accessed all the time.

The NullPointerException indicates a bug in the application. By the very reason it occurs, the current thread cannot continue execution normally. After a checked exception, it very much might. Though I would very much like to not have to handle exceptions in static initializer blocks - there is no good way to react to any problem happening there.

> "Slow" is an understatement. I don't see this happening at all.

All of this is slow-moving, I completely agree, but due to backwards compatibility concerns the ecosystem cannot be weaned off the issues that the JPMS is designed to prevent in a short time.

Re: Rating 26 years of Java changes

#280

Earlier quoted context omitted.

Kotlin didn't invent type inference, it's a feature from ML.

I never said Kotlin invented type inference, just that the syntax was straight adopted from kotlin

What syntax? val and var were used by Scala before Kotlin. Lombok also has val. Java just needed to pick a keyword.
Post reply on HN