[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Different shades of false
- From: Romulo Bahiense <romulo@...>
- Date: Thu, 02 Mar 2006 16:05:50 -0300
Dolan, Ryanne Thomas (UMR-Student) wrote:
Exactly. The only problem with nil/false is that people use these values incorrectly. nil is by no means synonomous with false, so it makes sense that nil ~= false. Being false and not defined are two very different states.
I agree. To me, this discussion is just like the one with NULL's in
RDBMS (1). NULL is not a value, it represents unknow, undetermined, not
present etc. It is not 0, it is not "", it is not false (in systems that
support boolean natively), it is not 0.0 nor it is ASCII NULL.
And to get worse, a table couldn't be checked for emptiness because it
may have a metatable which, incidentally, may have __index and
__newindex defined. It may be "physically" empty, but who knows what
those methods will return?
Consider:
userOptions = {}
groupOptions = {
sendEmail = true;
}
setmetatable(userOptions,{__index=groupOptions})
if userOptions.sendEmail then
mail.send{to = ..., subject = ..., ...}
end
Note that userOptions has no value inside it (no key, no value) but it
is not empty. It's "parent" metatable has the values. Also note that
'nil' is different from 'false', because 'false' would mean the user
don't want to receive e-mails, while 'nil' means he/she just don't care.
This discussion remembers me of some posts from The Daily WTF, where
now-and-then some smart guy declares something like:
enum Bool = (TRUE,FALSE,MAYBE)
--rb
1. Except, of course, to the fact that in Lua, nil==nil, while in some
RDBMS, NULL <> NULL.