[Gc] C++ API enhancement proposal

MenTaLguY mental at rydia.net
Tue Oct 16 11:20:01 PDT 2007


On Tue, 16 Oct 2007 09:28:34 +1000, skaller <skaller at users.sourceforge.net> wrote:
> .. but you realise your 'process' is actually multiple
> synchronised Erlang programs and the OS is called the
> Internet ..

Even in Erlang, you can't completely escape node-locality.
Actually, Erlang is a particularly bad example if you want
to argue against the utility of singletons, since much of
OTP is built atop named singleton processes.  Even for
distributed applications -- hence the 'global' module in
the kernel application.

To be fair, I don't think singletons are universally
required, so it should be possible to write a distributed
application without some kind of arbitration by designated
processes.  I just can't think of any real examples off
the top of my head.

> Or, your client decides to compare Linux with Windows,
> you wouldn't want to rewrite all that code because you
> used a global variable for 'the' operating system model.

Rewrite what code?  On Linux or Windows an "OS object"
can present the same interface, regardless of which
concrete class implements it (which, for C++, would
likely be determined at compile-time).  Only non-POD
globals dictate a fixed concrete implementation.

To be clear:

 1. singletons are *sometimes* an appropriate technique
    for OO modeling (I try to minimize their use in
    my own code)

 2. singletons in C++ should not be implemented using
    non-POD static variables (global or otherwise)

-mental



More information about the Gc mailing list