From: dave@boostpro.com   
      
   on Sun Nov 25 2012, fmatthew5876 wrote:   
      
   > Dave wrote:   
   >> I think Singleton is now officially an anti-pattern, bad for testability   
   >   
   > Anti-pattern or not there will always be a need for managing global   
   > state.   
      
   Perhaps. Even so, hard-coding that state's global-ness into the system   
   has proven to have long-term costs that most people don't anticipate at   
   the time they introduce it. Oh, and did I forget to mention that global   
   state inhibits parallelizability?   
      
   > Some applications like games use the singleton or global variable   
   > pattern if you will to great effect. If I have a function that needs to   
   > render an object, play a sound, and add physics object to the collision   
   > system, I don't want to create 3 new function parameters for the   
   > managers of all of these sub systems.   
      
   Globals definitely come with short-term syntactic gains. There are   
   various ways of dealing with the syntactic costs of avoiding them, but   
   it takes some work. IMO that work is well worth the trouble.   
      
   > I guess the term "singleton" is a bad use of words here because it   
   > implies the a class that can only be instantiated once by hacking around   
   > the dark corners of the language.   
   >   
   > The real question is how do we effectively expose and encapsulate global   
   > state.   
      
   Answer: in a way that makes it easy to un-globalize later ;-)   
      
   --   
   Dave Abrahams   
   BoostPro Computing Software Development Training   
   http://www.boostpro.com Clang/LLVM/EDG Compilers C++ Boost   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|