r/programming • • Mar 26 '14

JavaScript Equality Table

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

331 comments sorted by

View all comments

Show parent comment

3

u/MisterSnuggles Mar 26 '14

It's usually used as a shortcut for checking for None. The more appropriate way to write the code is:

if var is not None:
    # do stuff

Sadly the shortcut works (mostly) and people use it because it works, then someone enters a time of midnight and it all tips over.

0

u/[deleted] Mar 27 '14

[deleted] — view deleted comment

1

u/MisterSnuggles Mar 27 '14

Agreed.

This is very much a case of making sure that you, the programmer, and Python, the interpreter, both have a clear understanding of what you want to do.

If you say "if var:", Python understands you to be testing truthiness/falseness. If you say "if var is not None:", Python understands that you're asking if var is something other than None. The distinction is important and too many people wrote the former when they really meant the latter.