[cap-talk] Singletons Considered Harmful

Raoul Duke raould at gmail.com
Tue Mar 30 16:48:48 PDT 2010


> What do you mean by "global to methods"?
> If you are talking about instance fields (e.g., in Java, a field
> declared "private" but not "static"), I don't follow your reasoning.
> Why do you think the arguments against singletons apply to instance
> fields, too?

one is acknowledging that ambientness is useful when one uses instance
fields. of course, it is all a matter of degree, and perhaps when
ambientness is kept to a small enough region (even methods have local
variables ;-) then it isn't pure evil. but it makes me wonder where
the tipping point is. and i've seen entirely too much code that is
beyond the tipping point :-(.

i'm saying that if one doesn't like globals, then maybe one should not
be liking OO. or that at least the kind of OO that doesn't fall afoul
of the complaints against singletons is an OO that is cream of the
crop and all too rarely seen. i don't think that is a complete
indictment of OO, but i think it is a practical, valid concern.

* "singletons are just globals" -- within a certain context, yes, of
course, but: other processes which the code might talk to don't know
about them, much as at another fractal level of zoom, objects of
different classes don't know about the other's instance fields.

* "singletons make code hard to follow", "test", "maintain", "secure"
-- aspects of that are true for instance data, most obviously in
multithreaded contexts.

sincerely.


More information about the cap-talk mailing list