4 ms·
Is it really idiomatic to use intrinsic truth values (eg, using "if x" instead of "if x != 0")? Here are my arguments against it: - "Explicit is better than i
by rubergly 15y ago
Is it really idiomatic to use intrinsic truth values (eg, using "if x" instead of "if x != 0")?
Here are my arguments against it:
- "Explicit is better than implicit."
- If there's need for a table as reference for what is intrinsically true and what is intrinsically false, then it's clearly not "elegant" enough for people to just understand from looking at the code.
- Conventions vary across languages. You're basically forcing anyone who looks at your code who's not used tons of Python (and who would otherwise completely understand the code) to look up that table.
- billjings 15y ago- But readability counts. Having written a lot of Java and Obj-C lately, I honestly prefer the ability to write "if (foo && foo->bar && foo->bar->baz)" in the latter. - Frankly, it's not a very complicated table. "Zero, empty, or none" summarizes it pretty well. http://docs.python.org/release/2.5.2/lib/truth.html http://docs.python.org/release/2.5.2/lib/truth.html - Of course conventions vary across languages. If you're familiar with perl, awk, or ruby, some of these conventions will be familiar to you. If you're more familiar with Java, they'll feel odd and you'll feel an uncertainty using them.