lua-users home
lua-l archive

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

On Tue, Jul 31, 2018 at 12:00 AM, Sean Conner wrote:
It was thus said that the Great Egor Skriptunoff once stated:
> On Mon, Jul 23, 2018 at 11:48 AM, Dirk Laurie wrote:
> > I call it first one "semi-global variables". All upvalues that are
> > intended to have scope of the entire file are collected near the top of
> > the program with no initializer. They tend to have fairly long,
> > descriptive names, not just 'x'.
> Declaring all "pseudo-global" variables at the beginning of a program isn't
> a good idea, IMO.
> (Even in Pascal you can declare a global variable anywhere in the code.)
> More convenient approach is to define a variable at the line where the
> variable is really starting to be needed.

  I'm not sure what variants of Pascal you are used to, but for the ones I'm
used to, you can only declare new variables at the top of code block, not
anywhere in the code.

Strictly speaking, you are correct: global variables in Pascal must be declared near the beginning of a file.
But local variables declared inside implementation section of (rather long) pascal unit do smell like globals to me: their scope covers almost whole file.
And I incorrectly call them "globals".
They're exact counterparts of Dirk's "semi-global variables".