[OT] my experience with nullable types (C#)

Sebastiaan Koppe mail at skoppe.eu
Wed Apr 30 09:41:04 UTC 2025


On Wednesday, 30 April 2025 at 07:17:37 UTC, Kagamin wrote:
> Finally I had my chance to cope with nullable types in one of 
> our C# codebases, and the experience wasn't nice.
>
> I had a prejudice that nullable types give some kind of promise 
> that you will have only a few of them, but now that I think 
> about it I can't remember anyone making this promise, and 
> reality is quick to shatter this prejudice in a very ugly way.
> If you have a nullable type, all code now sees it as nullable, 
> and you must insert null checks everywhere, even if you know 
> it's not null by that point, and the volume of this null check 
> spam is uncomfortably large. It's also not very clear what's 
> the difference between me spamming null checks everywhere by 
> hand and processor doing the same automatically.
> Nullable types are retrofitted in dotnet and all legacy 
> interfaces return nullable types, this greatly increases number 
> of null checks.

I had the complete opposite experience in Kotlin, where the 
default are non-null types.

It was a joy to work with. The nullability checks only came up 
when interfacing with Java code, but one way or another, you have 
to deal with nulls coming from Java anyway, either at compile 
time, or at debug time ;)


More information about the Digitalmars-d mailing list