From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2008-01-17 13:28:29
Anthony Williams wrote:
> Tobias Schwinger <tschwinger <at> isonews2.com> writes:
>> Anthony Williams wrote:
>>>>> I've written code that used singletons (and regretted it later), and used
>>>>> code that other people have written containing singletons.
>>>> So you should like this library: The design chosen allows you to easily
>>>> substitute Singletons with Smart Pointers.
>>> I disagree. If people know something is a singleton, then they don't bother
>>> keep the reference around, as they can get it again later. Changing code
>>> does that to code that can use a passed in instance requires adding
>>> and/or storing references. You can't just change uses of a singleton to use a
>>> smart pointer instead without thought to *how* it's being used.
>> I won't argue on this one. I can imagine that having to refactor a mess
>> like this is a most unpleasant experience.
>> Still it's not the fault of the Singletons but of developer's laziness:
>> At least the developers in the project you mention had a choice whether
>> to write flexible code or not. With globals and static functions, they
>> wouldn't have had a choice but to make a mess.
> Singletons *are* globals.
OK, that was a bit unclear. Let's put it this way:
It's not globals that are evil but accessing them all over the place
(or "coupling" to use the technical term that describes the problem).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk