|
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. —Tim |