|
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 (Pythonand PHP) use local by default.Visual Basic, C, Java, C++, C#, and Delphy have no default, although ifyou say nothing inside the function the variable can yet be global butcannot be local, so they seem nearer to a "global by default". Perl andJavaScript 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