lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 04/12/2012 13:59, steve donovan wrote:
On Tue, Dec 4, 2012 at 2:40 PM, spir <denis.spir@gmail.com> wrote:
One more point for genuine bools ;-) (hum...)

One of my most common errors is to say 'if foo then ... end' when I
_really_ mean 'if foo==nil then .. end'.

Kind people then write to me to ask why I am so prejudiced against
genuine false values.

But still, just because it's a common sloppy mistake, does not mean
that the language itself must make it impossible to be sloppy.

In general, I try and write systematically 'if foo == nil then' when foo isn't a boolean.
I keep the sort notation for pure boolean variables.
It is annoying to type, but it can prevent such errors.

Now, my logic is flawed, because I still use idioms like:

    filenameIn  = (arg and arg[1]) or "-"

:-)

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --