Miguel has over 10 years of experience with Microsoft Technologies. Specialized with many things in the Microsoft ecosystem, including C#, F#, and Azure
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
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.
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
andOption
in all our method's signatures. Doing so makes the returns very explicit for the caller instead ofExceptions
andnull
which are implicit.Option<int>
-> Returns aint
or not. e.g.GetById
Either<string, int>
-> Returns aint
in case of success andstring
in case of failure with the error messageStructs are a different story. Why would I use
Option<int>
whenNullable<int>
(orint?
) is an option? It clearly expresses that it may not return a value.LanguageExt will force you to deal with null values,
int?
won't. Also lots of extension methods to deal with optional types.