Re:Lua: Good, bad, and ugly parts
by vor_ on Saturday March 09, 2013 @05:04PM
(#5349780)
You don't consider it an inconsistency for (1) and (not 0) to evaluate to different results?
[ Parent
| on HN ]
Re:Lua: Good, bad, and ugly parts
by Stratoscope on Saturday March 09, 2013 @07:55PM
(#5350206)
(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.
Obviously 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.If 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.
Would you consider that an inconsistency if you weren't coming from the C paradigm of 0 == false?
Yes, because it's not just a C paradigm. Additionally, even though 1 is true, comparing 1 and true returns false!
Re:Lua: Good, bad, and ugly parts
by Stratoscope on Saturday March 09, 2013 @07:58PM
(#5350215)
1 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.
I'm aware of the reasons why. It's still inconsistent to users. Remember that Lua is targeted at non-professional programmers.
Re:Lua: Good, bad, and ugly parts
by jmaygarden on Saturday March 09, 2013 @08:38PM
(#5350332)
In 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.
0 isn't false.
It'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.Stop 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)