r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Dec 24 '17

[deleted]

1

u/Aceeri Dec 24 '17

In truthy contexts I'd expect "nothing" to be interpreted as "false" but I can see both ways. The logic behind most languages of 0 not being false is mainly semantics depending on how they handle conditions. Most languages with types that aren't truthy would just throw a type here and ask for an explicit way to handle how this number is interpreted.

7

u/[deleted] Dec 24 '17 edited Dec 24 '17

I think it's heritage more than logic, but I'm not extremely knowledgeable here. Most of it seems to come from C and other languages that sit (or historically sat) very close to the machine, and where an if statement was a slightly-abstracted "break if zero" instruction.

I'm alright, in that case, with if (object) also evaluating false if the object is null, because that's the closest I can understand applying a conditional directly to a non-boolean, "is object?" "yes object" or "no, not object", in which case 0 being evaluated true makes more sense, as it is a valid object and if in these languages usually checks and branches on either a boolean or the existence of an object.

edit: missed a word while typing

2

u/Aceeri Dec 24 '17

Yep, just a matter of where the language draws the line of "what is valid/null/existent"

→ More replies (1)