lua-users home
lua-l archive

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


> So, that issue should probably evolve into the question: Should access
> to undeclared variables be allowed? Or the similiar: Should there be a
> standard way to disallow it? The issue that follows from this is that
> unless one adopts a draconian policy of only allowing a specific white
> list of values, then there needs to be some way to declare a global
> variable in addition to declaring a local variable.

For me this issue has been settled a long time ago. The problem
in "anything-by-default" is not the choice of "anything", but the
"by-default".

However, declaration of globals in the chunk level is mostly useless for
read opeations. If you misspell a variable name, there is a good chance
you will misspell it in the declaration too. (Probalby you will do
copy-and-paste to add the declaration.) It is like declaring variables
in C directly in the .c files instead of in a .h (plus the common good
practices around the usage of .h files). Moreover, any basic test should
detect such misspelling.

I still think the main problem is non-intended assignment to globals,
which creates hard-to-find bugs. The simple policy of requiring a global
declaration to assign to globals would force programmers to consider
whether they really want a global variable.

-- Roberto