News for hackers. Stuff that matters.
Re:JVM/Java: Null-Restricted and Nullable Types by pjmlp on Friday August 02, 2024 @07:42AM (#41137996)
As someone that works across JVM, CLR and Web ecoystems, dealing with C# approach is still a mess, unless one is lucky enough to only work in greefield projects.

It is made worse, by being a C# 8 feature and not usable in libraries that need to stay compatible with .NET Framework (yep still plenty of stuff going on there).

Re:JVM/Java: Null-Restricted and Nullable Types by ygra on Friday August 02, 2024 @07:51AM (#41138068)
AFAIK you can still use it for older frameworks. The compiler embeds the attributes into the assembly when they're known to not be part of the runtime library [−3.7]. You can do the same with the various conditional nullability attributes.

[−3.7]: https://sharplab.io/#v2:EYLgHgbALAPgAgZgARwExIMJIN4FgBQSRKyc...

Re:JVM/Java: Null-Restricted and Nullable Types by pjmlp on Friday August 02, 2024 @08:53AM (#41138458)
Yeah, those are the kind of tricks I don't like playing, because when things break down, someone has to sort out the mess.
Re:JVM/Java: Null-Restricted and Nullable Types by jacobparker on Friday August 02, 2024 @11:51AM (#41139877)
The one nullable gotcha with doing this is that the .NET standard library doesn't have nullable annotations in older frameworks.

One approach to adding nullable annotations to a large code-base is to go "bottom-up" on DLL at a time. The annotations are somewhat viral; if you were to go top-down then as you get to more of the "shared" DLLs and add annotations you'll find yourself having to go back and revisit the DLLs you already migrated. In this light, the .NET standard library situation is problematic.

Imagine implementing IEnumerable<T> by wrapping another IEnumerable<T>; in .NET framework there are no nullable annotations, so you can get into a situation where you don't add a nullable annotation where you will eventually need one upgrading to newer .NET. This can bubble up throughout your code base, making that eventual .NET upgrade more challenging.

I'm not saying its not worth it to do this in .NET framework, but you can very easily add extra work to the inevitable(?) update to .NET 8+. When you get there you could of course temporarily regress and turn nullable stuff back to warnings until you work through that surprise backlog, but nullable is really nice so you might be strongly inclined to not do that... not a huge problem, just something to be aware of!

Re:JVM/Java: Null-Restricted and Nullable Types by ygra on Friday August 02, 2024 @03:03PM (#41141615)
Yeah, I've been through that recently as well. The fix for now was to temporarily switch to .NET 8, apply a code fix that adds the inherited nullable annotations throughout the whole solution and revert back to .NET Framework 4.8.

This shouldn't be a problem when multi-targeting, but we've opted to not use that for now for other reasons (performance in Rider, mostly).