It's not rare. If you're coding a CRUD, and you want to test whether a particular field is null in your database, the canonical way to do it is to if it. That works 99% of the time, except when dealing with datetime objects.
In fact, Python's datetime module is chock full of wtfs.
One common reason to do it would be to validate input or take some kind of default action if input wasn't provided.
I used to write a lot of stuff like this (until I saw the false midnight thing):
def do_stuff(at_time=None):
if at_time:
# schedule stuff to be done at at_time
else:
# do stuff immediately
It's a contrived example, but "obvious" (in quotes because it's not at all obvious that midnight means do stuff immediately in this code) code like the above will normally do exactly what you'd expect it to do. Then someone will want their stuff done and midnight and be shocked when the function does it right away!
17
u/MisterSnuggles Mar 26 '14
While not JavaScript, we must not forget about Python's False Midnight.
tl;dr:
Prints "f".
Prints "t".