5 ms·
Numerous bugs on github were attributed to the guy with user name 0. He evaluates to false in many PHP applications, too.
by solox3 13y ago
Numerous bugs on github were attributed to the guy with user name 0. He evaluates to false in many PHP applications, too.
- gtaylor 13y agoDitto for Python (int 0 at least).
- dorfsmay 13y agoWeird, because makes a distinction between int and string.
- masklinn 13y agoPython makes a distinction between types, but it has a concept of falsyness (as do many languages, though it is often more restricted e.g. in Ruby only false and nil are falsy IIRC). Falsyness is used in boolean-ish contexts (if, while and explicit boolean conversion), by default all of None (null), False, 0, 0.0, "" (the empty string, unicode or binary) and empty collections ([], (), {}, set()) are falsy and although UDTs are "truthy" it can be overridden. This has nothing to do with making the distinction between ints and strings. You could actually implement the same thing in e.g. Haskell (by creating a "Booleanish" typeclass and implementing it on all the types you care for). edit: please note that — in Python — 0 (the integer) is falsy but "0" (the string containing a single character 0x30) is truthy. I expect gtaylor talks about bugs in handling of IDs or sequence numbers and the like, not usernames. I know I've hit them when not being very attentive.
- Dewie 13y agoGForth uses 0 for 'false' but -1 for 'true'... that confuses me a lot.
- IanCal 13y agoI suppose it's because then it can just compare the first bit.
- deleted 13y ago[deleted]
- dlitz 13y agoBASIC does that, too.
- kybernetikos 13y agoI expect that it's because in twos complement representation -1 is represented as all bits set.
- alwaysdoit 13y agoYeah, but "0" is True. Why would you store a name as an int?
- recursive 13y agoIn python 0 is falsy. "0" is not.