6 ms·
Nullable is a huge issue in Java, but annotation-based nullability frameworks are both effective and pervasive in the ecosystem (and almost mandatory, IMO). I'
by leapis 3y ago
Nullable is a huge issue in Java, but annotation-based nullability frameworks are both effective and pervasive in the ecosystem (and almost mandatory, IMO).
I'm really excited about https://jspecify.dev/ https://jspecify.dev/, which is an effort by Google, Meta, Microsoft, etc to standardize annotations, starting with @Nullable.
- mrkeen 3y agoI was just writing about nullability annotations! https://news.ycombinator.com/item?id=37534184 https://news.ycombinator.com/item?id=37534184
- wayfinder 3y agoI hope they succeed. So many people have tried.
- mrkeen 3y agoNot having nulls is easy. Persuading Java devs not to use nulls is hard.
- kaashif 3y agoThis can never be as effective as changing the default reference type to be not nullable, which would break backwards compatibility, so you can never really relax. I know Kotlin is basically supposed to be that, it has a lot of other stuff though, and I haven't used it much.
- martindevans 3y agoThat's basically what c# has done. But it's implemented as a warning which can be upgraded to an error. I think it might even be an error by default in new projects now.
- kaashif 3y agoHoly shit, how didn't I know they'd taken it this far? This is great! https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts https://learn.microsoft.com/en-us/dotnet/csharp/nullable-ref... They actually fixed the billion dollar mistake...
- 5e92cb50239222b 3y agoThey didn't. A proper fix would require getting rid of null altogether in favor of ADTs or something similar. I work with C# daily and nulls can still slip through the cracks, although it's definitely better than @NotNull and friends. I haven't worked with Kotlin in a while, but IIRC their non-nullable references actually do include runtime checks, so you cannot simply assign null to a non-nullable and have it pass at runtime like you can (easily) do in C#.
- foolfoolz 3y agothey won’t change the default reference type to non null. might take a few years but you can see their planned syntax here: https://openjdk.org/jeps/401 https://openjdk.org/jeps/401
- netheril96 3y agoNullable annotations don’t work with well with generics, or at least those tools I use.