I didn't say don't use null
. I said don't return null
NULL can be useful in a data structure, and to use your example in a Person of Name class having null for the middle name could be (I won't say "is") better that "NMN" (No Middle Name) or similar. The question is what helps save [my] behind. There are times when "yoda conditionals" make sense. There are use cases where they don't. I didn't specifically chime in on that discussion because I can see both sides and use (or not) depending on readability and what is being tested for. Returning null, in my not so humble opinion, is a code smell. Using null in a data structure is not. But ultimately, it depends on the team's (or single developer's) style and agreements. And do you accept the related overhead - null checks (or Elvis operator), or try ... catch.
T
TrinityRaven
@TrinityRaven
Posts
-
do any of you others have little coding mantras that save your behind? -
do any of you others have little coding mantras that save your behind?Different use cases. I’m stuck debugging an app that is crashing because NULL is not a valid value. A part of what makes programming fun (?), is the various ways to solve a particular problem.
-
do any of you others have little coding mantras that save your behind?Don't return
null
. Throw an exception instead. Removes need to null check everything. Hopefully give a more meaningful error when a problem occurs. -
When (or not) did you learn about the Sieve of EratosthenesFrom Carl Sagan's Cosmos (original version)