[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "static" declaration
> What are the data structures? What are
> the relationships between them?
> ...
> Basically, I am learning the code by understanding it bottom-up.
> Once I see what state is stored in each class of object, I can
> better express in my head what the object really represents.
as also said by Brooks:
(in ye auld tongue)
_The Mythical Man-Month_ [Chapter 9]
> Much more often, strategic breakthrough will come from redoing the
> representation of data or tables. This is where the heart of a program
> lies. Show me your flowcharts and conceal your tables, and I shall
> continue to be mystified. Show me your tables, and I won't need your
> flowcharts; they'll be obvious.
so it would make sense that it's
better to keep explicit listings
of data representations, such as
instance variables:
> The conventional "new" methods in Perl usually [initialize], mostly,
> generally, but then sometimes some other method tacks on some more
> instance variables later on, so, you just never know. Never knowing
> is not, in my opinion, a good thing.
However, Kernighan remarks that
gathering declarations together
can also be over-done:
"Why Pascal is Not My Favorite Programming Language"
[2.2. There are no static variables and no initialization]
> A 'static' variable (often called an 'own' variable in Algol-speaking
> countries) is one that is private to some routine and retains its
> value from one call of the routine to the next.
> ...
> Pascal has no such storage class. This means that if a Pascal function
> or procedure intends to remember a value from one call to another,
> the variable used must be external to the function or procedure.
> Thus it must be visible to other procedures, and its name must be
> unique in the larger scope. ... In practice, this is typically
> the outermost block of the program. Thus the declaration of such a
> variable is far removed from the place where it is actually used.
> ...
> The declaration, initialization and use of [such a variable] are
> scattered all over the program, literally hundreds of lines apart.
> In C or Fortran, [the variable] can be made private to the only
> routine that needs to know about it ...
summarized as:
> The lack of static variables, initialization and a way to communicate
> non-hierarchically combine to destroy the ``locality'' of a program -
> variables require much more scope than they ought to.
(and a global static that is "local"
to a procedure or two is similar to
an instance variable that is "local"
to a method or two)
Where does the balance lie? Does
a sufficiently flexible IDE make
the question moot?
-Dave