lua-users home
lua-l archive

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



On Aug 4, 2005, at 20:32:49, Roberto Ierusalimschy wrote:

which is pretty much the opposite of the major languages?
So far I thought it was safer if variables are local by default, [...]


I am not very sure, but I think that, of the 10 most "major" programming languages (according to http://www.tiobe.com/tpci.htm), only two (Python
and PHP) use local by default.

Visual Basic, C, Java, C++, C#, and Delphy have no default, although if
you say nothing inside the function the variable can yet be global but
cannot be local, so they seem nearer to a "global by default". Perl and
JavaScript have global by default.

That may depend on where you're actually declaring the variable. Variables declared inside methods, classes and functions are definitely local in scope in C, Java, C++ and Pascal. I'd be surprised if Delphi behaved differently in this regard than Pascal did. That variables declared outside those are global IMHO simply happens because that is the *only* way to declare a global in the C- descended languages. It's been a while since I did Pascal, but I think there they actually have a dedicated header section for globals, so there's no "automatic global" there at all.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de