lua-users home
lua-l archive

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

On Jan 9, 2015, at 11:28 PM, behoffski <> wrote:

Going directly to the current NULL/nil-less-versus-exceptions discussion,
my feeling is that in a world of diverse libraries and reuse scenarios,
adding an exception facility to Lua, in order to eliminate the appearance
of nil, wouldn't be pleasant:  A library may throw an exception that you
weren't expecting (the initial Ariane 5 rocket failure is an extreme case
of an unexpected exception being part (but not all) of a complex failure

This entire discussion seems to be based on the logic “NULL is bad, nil is like NULL, therefore nil is bad.” But nil is really nothing at all like NULL, so imho the rationale of the OP is flawed.

In C, a NULL pointer is associated with a certain risk in that if the code dereferences it, the program may (should?) crash. There is thus some validity in treating NULL with care, or using techniques to avoid it (like references in C++). For another interesting approach, see the use of optionals in Swift (which I suspect are not original to Swift, but are reasonably well thought out). Note, however, that this is a quite different discussion from uninitialized pointers, which also seem to have somehow crept into the thread.

In Lua, a nil value does not exhibit any deviant behavior. My understanding of the OP is that he equates a nil value with “uninitialized variable”, which is not true at all. A variable with a nil value is indeed initialized, to the very real Lua value of nil. And since Lua is careful to default all variables to nil, there is no such thing as an uninitialized variable in Lua.