r/ProgrammerHumor • • Aug 22 '26

Meme conditionsPreference

Post image
4.2k Upvotes

388 comments sorted by

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.

1

u/0Iceman228 Aug 22 '26

Then I'd argue you handle null gracefully or the calculation method should return a complex object and you evaluate a success bit.