[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Behavior of logical operators
- From: Axel Kittenberger <axkibe@...>
- Date: Mon, 14 Mar 2011 12:02:59 +0100
> In C/C++ I would write !!condition. In Lua "not not condition" ?
I'm not sure how the ! operation is exactly defined in C(++)
standards, is the result guaranteed to be 1(true) and 0(false) or just
the usual 0 in case of false, or anything else in case of true. If it
is the second, you gain nothing by !!. In C I'd write (condition ? 1 :
0); if I want to fix true to 1, or (condition ? true : false) in C++.
Additionally I challenge "not not" to be a more elegant solution, yes
it is shorter, but the usual reader/debugger that is not you has a
"WTF moment", when reading it, requiring additional parsing/puzzeling,
while if condition then x = true else x = false; is straight easy.
If for "complex condition" you do not rely on Luas unfortunate
condition of having 2 false values, nil or false, but just test for
anything to be not nil, just write ~= nil into the condition, it comes
clear what you mean and the result is defined to be true or false.