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 comments

1

u/moor-GAYZ Mar 27 '14

If someone subclasses my stuff and adds a nonsensical __nonzero__/__bool__

2

u/NYKevin Mar 27 '14

What if they add a perfectly sensible __bool__ that nonetheless is incorrect in the context you wrote if foo? For instance, one that makes the class truthy or falsey based solely on data which was not part of the original class.

1

u/moor-GAYZ Mar 27 '14

It's hard to discuss this in abstract.

As I said, if I want an "is None" comparison, I write an "is None" comparison. I write a truthiness comparison when it makes sense to do one (even if I do not currently have objects that support it). Then it's on the users to not add a truthiness operator that only makes sense in their special context instead of implementing the general "false means no data" idea.

So, I don't know, say, if somebody gives me a "find_person(name)" function, it would be nice to allow them to return a rich "nobody found by that name" object instead of plain None if they want. More Pythonic. I'd rather allow that instead of allowing someone to make a Person class that evaluates to False if they have not submitted their yearly performance evaluation report yet.

1

u/NYKevin Mar 27 '14

Personally, I'd have the find_person() function raise an exception in that case (probably KeyError or ValueError). Besides, why do you need a rich empty object when None exists?

→ More replies (0)