3 ms·
There are several languages that only allow booleans in such comparisons. There you can't do e.g. a bare: if (a) for things that e.g. in C/Java etc would b
by coldtea 5y ago
There are several languages that only allow booleans in such comparisons.
There you can't do e.g. a bare:
if (a)
for things that e.g. in C/Java etc would be "truphy" (like 0, null, etc). Instead you need to do:
if (a != null)
(that is, check with an expression that returns an actual boolean true or false, not anything truthy/falsy that "coerces" to true/false).
In the same way, where in Python you'd do:
a = ""
if not a:
print "this will be printed"
there you'd do it like:
if not (a == "") -- or if not a.isEmpty():
...
or some such.
- mcphage 5y agoSure, but then "truthy" for that language is just true, and "falsy" is just false. It's still relevant to understand the concept of "what is considered true, and what is considered false", even if the answer is simple for certain langauges.
- coldtea 5y ago>Sure, but then "truthy" for that language is just true, and "falsy" is just false. Sure, but this stretches the meaning of "truphy" and "falsy", which was invented to describe the extra coercions to true/false. A language only allowing explicit true and false just has a concept of true and false, not of truthy and falsy.
- mcphage 5y agoTruthy is "what is considered true in a conditional". It’s still a meaningful question, with a meaningful answer, even in languages where the only thing truthy is the value true.
- IshKebab 5y agoIf "what is considered true in a conditional" is literally only `true` then a language has no "truthy" values. I mean, you're free to interpret it how you want but nobody else would agree with your definition.
- mcphage 5y agoWell, the people who read or write for this site would agree: https://developer.mozilla.org/en-US/docs/Glossary/Truthy https://developer.mozilla.org/en-US/docs/Glossary/Truthy. So not nobody.
- mcphage 5y ago> this stretches the meaning of "truphy" and "falsy", which was invented to describe the extra coercions to true/false Do you have a citation for this? I’m looking for a source which doesn’t consider true to be truthy, or false to be falsy, and I’m not finding one.