5 ms·
You don't consider it an inconsistency for (1) and (not 0) to evaluate to different results?
by vor_ 14y ago
You don't consider it an inconsistency for (1) and (not 0) to evaluate to different results?
- Avshalom 14y ago0 isn't false.
- vor_ 14y agoIt's also not true: > if 0 then print "true" end true > 0 == true => false I know why this is the case. But it's a logical inconsistency for users of the language.
- ufo 14y agoStop trolling please. You are advocating for `==` doing type coercion of arguments and that is almost always a misfeature in any language that has that (and the fix usually involves adding an ugly `===` operator after the fact)
- akavi 14y agoWould you consider that an inconsistency if you weren't coming from the C paradigm of 0 == false?
- vor_ 14y agoYes, because it's not just a C paradigm. Additionally, even though 1 is true, comparing 1 and true returns false!
- Stratoscope 14y ago1 is not the same value as true. Just as in the case I commented on a couple of messages above, 1 and true are two different types. The == operator does not compare the "truthiness" of two values. It compares the values, and if those values are two different types, they are always unequal. http://www.lua.org/pil/3.2.html http://www.lua.org/pil/3.2.html
- vor_ 14y agoI'm aware of the reasons why. It's still inconsistent to users. Remember that Lua is targeted at non-professional programmers.
- jmaygarden 14y agoIn my opinion, having (1==true) evaluated to true, but (2==true) evaluate to false is more inconsistent. Even non-professionals should follow logic if they are going to program.
- Stratoscope 14y ago(1) is a number. (not 0) is (false), a boolean. How could they be the same? They must be different because they are different types.
- vor_ 14y agoObviously there are reasons for the behavior, but it's still inconsistent to users who are exposed to your scripting API to have: if 1 then print "true" end if 1 == true then print "never prints" end Not a reason to avoid the language. But it may be a reason to consider an alternative with more conventional behavior.
- omaranto 14y agoIf you replace 1 with 2 this is an argument against using a vast number of languages, including Squirrel, I think. So maybe you're really saying that languages should forbid non-Boolean values in if statements. Maybe I agree with that.
- klibertp 14y agoIn the case of Lua rules of what is truthy and why (as I read here) I'd expect (not 0) to be a type error. That's the case in OCaml for example and I think it would be good in Lua.