DEV Community

Discussion on: Why null in C# is so bad

Collapse
 
mbernard profile image
Miguel Bernard

I use Language-ext (github.com/louthy/language-ext) in all my projects now. It has made our code more readable and less error-prone using Either and Option in all our method's signatures. Doing so makes the returns very explicit for the caller instead of Exceptions and null which are implicit.

Option<int> -> Returns a int or not. e.g. GetById
Either<string, int> -> Returns a int in case of success and string in case of failure with the error message

Collapse
 
thebuzzsaw profile image
Kelly Brown

Structs are a different story. Why would I use Option<int> when Nullable<int> (or int?) is an option? It clearly expresses that it may not return a value.

Collapse
 
buinauskas profile image
Evaldas Buinauskas

LanguageExt will force you to deal with null values, int? won't. Also lots of extension methods to deal with optional types.