lua-users home
lua-l archive

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

	Here are some of my opinions about variables and scope.

	Global variables are evil, they tend to block the reentrance of
functions. They can be unadivertadly overwriten by calling a function
that uses the same global as if they were locals (just to save the work
of declaring them). 

	Undeclared use of variables are also a bad thing, shure they save time
of the lazy (including me), but they can cost a day or two if you
mispelled a single char in a long program. I do like them for quick
prototypes and the like.

	And here are some of my sujestions for the new version of lua.

	A mode, or a sencond compiler, that will warn about common errors. Like
reading a undefined variable.

	Each table should allow a parent table, one that will be used to look
for undefined values in the child table. 

	Since there is two kinds of variables, a fast predeclared and a slow
auto-generated. I would sugest that the user could declare both local
and globals, every declared variable would be created in compile time.
The undeclared variables are created at atribution time, if there is a
table for the current block the variable will be stored there, otherwise
a new table will be created for this block with the parent table set to
the last "local table" created. 

	Variable lookup would be recursive, search each "local table" for a
defined value until you reach the "global table", if the variable is not
defined then return nil.

	In my opinion this will be an incentive to declering variables, since
it will make the program run faster. It will have local by default. And
I think it would not have a huge impact in performance, since most
program would have only two levels of "local tables".

[]'s Victor Bogado da Silva Lins