[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Globals vs. Locals
- From: Uli Kusterer <witness.of.teachtext@...>
- Date: Fri, 5 Aug 2005 20:33:27 +0200
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"
languages (according to http://www.tiobe.com/tpci.htm), only two
and PHP) use local by default.
Visual Basic, C, Java, C++, C#, and Delphy have no default,
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
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.
-- M. Uli Kusterer