On 1/9/06, Lyndon Samson <lyndon.samson / gmail.com> wrote:
> On 1/10/06, David Vallner <david / vallner.net> wrote:
> > The main advantage of instance variables to global variables is that
> > they allow you to scope the variables down to -very- narrow contexts of
> > validity, and they can be hidden outside said scope. If that's what you
> > mean by "more restrictive variation", then scoping is the restriction
> > that matters. And giving context to relate global variables via naming
> > conventions sounds pretty painful.
>
> I guess what I was thinking was, conceivably you could have a class with
> say 100s of methods, all with full access to any
> (private/protected/public) instance variables. How is that different to
> 100s of functions accessing global variables?

It's not. Both are bad design. However, in the case of the class +
instance variables, the problem is that you shouldn't have hundreds of
(significant[1]) methods in one class, that's a major code stink --
smell isn't a strong enough word.

Jacob Fugal

[1] At peril of reopening the "Array has too many methods" can of
worms; yes, I do like convenience methods; no, I don't think Array has
too many methods, although there are a *few* questionable methods in
Array; yada, yada, yada. The important thing is that convenience
methods *should* be built upon the other methods of the class, and
thus not access the instance variables. They are only there, as the
name implies, for convenience.