lua-users home
lua-l archive

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


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

> One possible downside of this is that this very simple Lua program:

> a = "Hello World"
> print(a)

> becomes:

> global a = "Hello World"
> print(a)

> (or "local a...").  Does this make Lua harder to learn?

While I really like mandatory global keyword, I'd also want

arbitraryName = "Hello World"

to work for some chunks with custom environments (i.e. config files).

It is not good to force config file authors to write

global NO, THANKS

at the start of file.

(Furthermore, they probably should have no say on the subject.)

Enabling global keyword by using it is not good either. (Also, too
obscure for my taste...)

Perhaps it should be an argument to the load*() function?

Alexander.