Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2008-01-16 03:04:59


Anthony,

thanks for your review.

Anthony Williams wrote:
> I don't think this is at all useful. People should not be encouraged to use
> singletons, as there is already a tendency towards overuse. In most
> circumstances, singletons are a poor design choice, so there is little
> requirement for their use.

Any design that's picked carelessly is poor or just at best a fluke.

Having a framework internally use some Singletons can greatly simplify
its use. Exposing a singleton to a user provides more flexibility than
exposing a static interface (and can also improve performance).

A "tendency towards overuse" is not a good reason to reject a library,
as it won't stop overuse and encourages more half-baked solutions that
are written in a hurry.

The only thing you can do against overuse is to add your experience to
the documentation in order to educate users about applicability.

>> * What is your evaluation of the design?
>> * What is your evaluation of the implementation?
>
> The design mixes several independent issues --- ensuring there is only one
> instance of a class and avoiding initialization order problems with on-demand
> initialization for starters.
>
> A simple wrapper class that allows for on-demand initialization, would be
> useful. Conflating that with "there shall be at most one instance" is not.
>
> Again, allowing for a preferred destruction sequence of objects with such
> on-demand initialization might also be useful, but does not belong with the
> one-instance constraint.

What is the point in managing construction order without static context?

What is the point of having more than one instance of a class that lives
in static context -- and how would it be captured syntacticly?

> thread_specific_singleton is overly complex for what should just amount to a
> simple use of thread_specific_ptr.

It uses 'thread_specific_ptr' and has additional responsibilities.

Could you be more specific, please?

> 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.

Regards,
Tobias


Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk