Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Checking Variable for Not Null

by sundialsvc4 (Abbot)
on May 27, 2015 at 15:39 UTC ( [id://1128024]=note: print w/replies, xml ) Need Help??


in reply to Checking Variable for Not Null

Another way to say it, is to say that the first example tests for “truthiness.”   As others have said, there are many possible values for $ex_date which are “false-y” but which are not what you are (intending to be ...) testing for.

And this leads to the very worst kind of bug:   the “it seems to work ...” bug.

Therefore, even though you are happily dealing with a “DWIM = Do What I Mean” language, you must sometimes be careful to “SWIM = Say What I (Really ...) Mean.”   This is one of those occasions.

And this, of course, is also in-keeping with a distinction that the SQL language is very careful to draw:   “NULL is not False.”   NULL is:   “the absence of any value at all, therefore neither True nor False.”   So, in your application logic, you should take careful pains to draw the same distinction.   Test for undef (NULL) “first, and explicitly.”   Test for “truthiness” (or better yet, for an explicit value ...) only after you have established that the value is not NULL.   Then, throw an exception (die()) if you encounter “none of the above.”   When debugging-time comes, you (or your successors) will be glad that you “went to all that ‘extra’ trouble.”

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128024]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-19 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found