lua-users home
lua-l archive

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

Mark Hamburg wrote:

In my experience with Lua, type errors are relatively rare, but typing
errors are common. What those seem to need are an easy way to detect:

* Undefined variables. The various Lua lints detect this by looking for
unexpected global access. The language could probably become friendlier
about this though that would have to be balanced against keeping the
language friendly toward incremental compilation. Perhaps "new" globals
should only be allowed at the top level of a chunk.

That's funny how some topics bubble up (?) frequently on this mailing list... Depending on the point of view, that may mean:
- that users express a deep need that must be addressed;
- that Lua is deeply incompatible with some ways of thinking, and users either should get used to this way, or use another language.

This proposal is quite close of the frequent request of "local by default". It can't be accepted "as is", because it would break some scripts. Don't forget that Lua is initially a configuration language, used to express dynamically data structures. With your proposal, some constructs would be impossible.
I suppose this could be addressed by a "global" keyword.

Anyway, this have been proposed many time, and always rejected by Lua authors, either because of compatibility, or because of fundamental philosophy of Lua, or some other reason I forgot...

Maybe this topic can go in the Lua FAQ:
There is already the "How can access of undefined variables be caught in Lua?" question, but this could be expanded a bit more.

A "Lua Philosophy" entry in the Wiki may clear these questions definitively?

"Why Lua variables are global by default?"
"Why this will no change?"
"Why there is nothing like Visual Basic's 'Option Explicit' to catch undefined variable uses?" (because it is simple to do it already: in the Wiki)
"Why does Lua lack the += operator, etc.?" (in the Wiki)
"Why there is no xxx feature like in my favorite language (switch, continue, etc.)" (there should be the workarounds as seen on the mailing list)

Most of these questions, and the related answers, are on the mailing list archive. If a good soul, with lot of time on his hands, and a good motivation, could search these and copy them on the Wiki, that would be nice.

Philippe Lhoste
--  (near) Paris -- France
--  Professional programmer and amateur artist
--  --  --  --  --  --  --  --  --  --  --  --