r/programming • • Mar 26 '14

JavaScript Equality Table

http://dorey.github.io/JavaScript-Equality-Table/
809 Upvotes

331 comments sorted by

View all comments

17

u/MisterSnuggles Mar 26 '14

While not JavaScript, we must not forget about Python's False Midnight.

tl;dr:

if datetime.time(0,0):
    print "t"
else:    
    print "f"

Prints "f".

if datetime.time(1,0):
    print "t"
else:    
    print "f"

Prints "t".

2

u/lambdaq Mar 27 '14

Okay, this is fucked up, guaranteed. But it's rare that someone would anyone if a datetime object, no?

7

u/yen223 Mar 27 '14

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.

3

u/MisterSnuggles Mar 27 '14

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!

→ More replies (4)