Google-apps
Hoofdmenu

Post a Comment On: C0DE517E

"Singletons: the new superglue"

5 Comments -

1 – 5 of 5
Anonymous Anonymous said...

Yes singletons are Evil.
But game programming is often ugly programming, mostly because users need more efficient code, forgetting about bugs.
I'd say singletons are good for quick'n'dirty code like prototyping

May 6, 2008 at 2:04 AM

Blogger FieldsOfCarp said...

Using singletons as globals is just plain wrong and on top of that inefficient. If you use a pure global the assembly doesn't have to check every time if the static has been initialised. I once read an interesting article by Herb Sutter in CUJ on "singleton pattern abuse". Unfortunately game programmers (not all of them) including me often can't be bothered to design software beyond their nose and establish clear ownership rules so globals, pardon, singletons will be around for some time.

May 6, 2008 at 2:59 PM

Blogger gpakosz said...

hmm to me, Singletons are more about controlling the instantiation phase of the object than about any need for a global shared state

the cherry on the cake is that you perform the initialization lazily the first time the object is actually needed

(sorry if i come late in the discussion :) )

September 8, 2008 at 1:06 PM

Blogger DEADC0DE said...

if so you should implement the pattern with a non-static instance getter, if you do singletons in that way, you'll quickly notice that they are way less "useful" and way less used... In practice, the singleton is, in my experience, always used as a shared state, with a fancy name.

September 8, 2008 at 11:30 PM

Blogger DEADC0DE said...

p.s. the lazy initialization thing is also a "bad" thing of that pattern, the pattern should be about having a single instance, it turns out to be about having shared state instead, plus it says something about initialization, making it (without any need) lazy... That's an extra thing that should not be in the pattern, it's not necessary.

In many cases people want to have an exact control of when they initialize and destroy such objects, so they simply implement singleton without lazyness.

September 8, 2008 at 11:33 PM

You can use some HTML tags, such as <b>, <i>, <a>

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot