News for hackers. Stuff that matters.
Re:Software development topics I've changed my mind on after... by pjc50 on Wednesday February 05, 2025 @06:22AM (#42946979)
It was botched from the start because there's so many opportunities for unchecked exceptions as well. Without a more sophisticated type system that represented nullability, you can get NullPointerException anywhere. Divide by zero. And so on.

You also have a problem similar to "monads and logging": if you want to log from anywhere in your program, your logging function needs to be exception-tight and deal with all the possible problems such as running out of disk space, otherwise you have to add those everywhere.

Re:Software development topics I've changed my mind on after... by jeroenhd on Wednesday February 05, 2025 @08:50AM (#42948468)
Unchecked exceptions are just Java's weird way of what languages call panicking these days. They suck, but as long as you don't throw them yourself and catch them in a logical place (i.e. at request level so your web server doesn't die, at queue level so your data processing management doesn't lock up, etc.) you can usually pretty much ignore them.

The worst part about them is that for some reason even standard library methods will throw them. Like when you try `list.Add(1)` on a list without checking if said list is read-only. The overhead of having to read every single bit of documentation in the standard library just to be ahead of panicking standard methods is infuriating.

That's got nothing to do with the concept of checked/unchecked exceptions, though, that's just Java's mediocre standard library.

Re:Software development topics I've changed my mind on after... by corytheboyd on Wednesday February 05, 2025 @10:39AM (#42950029)
> Without a more sophisticated type system that represented nullability, you can get NullPointerException anywhere.

I started working in Java a few months ago and holy shit does this stick out like a sore thumb. Null checks cascade down from gods domain all the way to hell. But oop we missed one here and caused an outage lol add one more! So much wasted human effort around NPE, and yet, we sit around in a weekly meeting getting yelled at about how stability needs to be taken more seriously. Hrm.

Re:Software development topics I've changed my mind on after... by pjc50 on Wednesday February 05, 2025 @11:11AM (#42950584)
C# half-fixes this with its nullable annotations. I say half-fixes, because the boundary between code that supports them and code that does not is leaky, so you can make a mistake that leaks a null into a non-nullable variable.

If you build an entire program with nullability checking on it's pretty great, though.

Re:Software development topics I've changed my mind on after... by corytheboyd on Wednesday February 05, 2025 @12:32PM (#42952074)
Java, or at least Lombok, seems to have a @NonNull annotation that does what I want— cause code not to build that fails the check, and forces propagation of the annotation.

Reality does indeed feel exactly like what you mentioned with C#, though. The annotation is going to be missing where it’s needed most unless something forces the whole project to use it.

Re:Software development topics I've changed my mind on after... by mands on Wednesday February 05, 2025 @12:52PM (#42952380)
check JSpecify (https://jspecify.dev) - it's the standardised null annotation package for Java. Intellij understands the annotations so you generally get decent null-checking across your codebase.

Even better, apply at the package level via `package-info.java` (unfortunately sub-packages need to be individually marked as well)

  @NullMarked
  package com.foo;

  import org.jspecify.annotations.NullMarked;
Re:Software development topics I've changed my mind on after... by YoshiRulz on Wednesday February 05, 2025 @03:51PM (#42954922)
Kotlin fixes the null handling problem too, and with the added benefit of being able to gradually migrate Java code.
Re:Software development topics I've changed my mind on after... by kelnos on Thursday February 06, 2025 @03:10AM (#42960202)
The problem there was really that Java confused unrecoverable errors with recoverable errors. NPEs and divide by zero should make the program abort (possibly with another, completely different mechanism to catch these if you really want to, a la Rust's panic handlers).

Recoverable errors should all be checked exceptions, and a part of each function's type signature. This would still be a huge pain to deal with, though, with the existing syntax.