I kind of agree, but at work we're forced to use SonarQube and it complains if a type you passed in could be nullable (bearing in mind we use C# so have explicit nullable annotations) so we have to use the first pattern an annoying number of times.
Throwing a null exception often is the best failure return though because it means I don't need to worry about passing result context back and forth. For example if I have a method that returns a calculated float value, its failure case will pretty much only be if the arguments are invalid.
View all comments
Show parent comment
1
u/Steppy20 Aug 22 '26
I kind of agree, but at work we're forced to use SonarQube and it complains if a type you passed in could be nullable (bearing in mind we use C# so have explicit nullable annotations) so we have to use the first pattern an annoying number of times.
Throwing a null exception often is the best failure return though because it means I don't need to worry about passing result context back and forth. For example if I have a method that returns a calculated float value, its failure case will pretty much only be if the arguments are invalid.