Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-01-16 04:56:12


On Jan 16, 2008 9:07 AM, Tobias Schwinger <tschwinger_at_[hidden]> wrote:
> Giovanni Piero Deretta wrote:
> > On Jan 15, 2008 12:21 PM, Anthony Williams <anthony_w.geo_at_[hidden]> wrote:
> >> John Torjo <john.groups <at> torjo.com> writes:
> >>
> >>> Today starts the formal Fast-Track review of the Boost.Utility/Singleton
> >>> library. This is a very useful utility, so I'm expecting lots of reviews ;)
> >>> * What is your evaluation of the potential usefulness of the library?
> >> 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.
> >
> > I consider singletons just another form of globals and thus bad style.
>
> Let's see:
>
> "I consider if, else, for, do, while and the ternary operator just
> another form of goto and therefore bad style."
>
>
> ;-)

Except that 'if', 'else' and friends are a *restricted* form of goto
(i.e. the 'structured' in structured programming) and are thus
acceptable. In general, a singleton hardly adds any restriction to
global (except from being thread safe). :)

>
> > [...]
> > What about a form of thread local singleton which can be replaced with
> > a scoped construct?
> > [ code snipped ]
> > In practice it is a form of dynamic scoping, which might be more
> > useful and flexible than a static singleton.
> > You definitely want this dynamic scoped object to be per thread.
> >
> > I haven't read Boost.Singleton documentation, maybe it already allows
> > such a functionality.
>
> I'm not sure I understand the purpose of the code provided, but it seems
> to be sufficiently trivial to implement the facility you describe on top
> of what's provided.
>

It was just a form of dynamic scoping (
http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping ).
Probably the code didn't communicate the intent well enough.

 And yes, it is would be trivial to implement on top of any kind of
singleton (actually you do not need much more than a thread specific
pointer).

My point was that I would feel less guilty using such a singleton (if
you can call it singleton at all): if you eventually discover that you
actually needed more than one instance, you have an escape hatch.

--
gpd

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