Page 1 of 1

removal of Singletons

PostPosted: 05 Jul 2013, 22:49
by paul424
In here I would be posting things regarding removal of Singletons.
Here are current singleton's class files :
{l Code}: {l Select All Code}
    tom@linux-jc3n:~/Opendungeons/opendungeons/source> ack 'Singleton<' | ack '.h'
    LogManager.h:41:class LogManager : public Ogre::Singleton<LogManager>
    Translation.h:18:class Translation : public Ogre::Singleton<Translation>
    ResourceManager.h:19:class ResourceManager : public Ogre::Singleton<ResourceManager>
    TextRenderer.h:10:class TextRenderer: public Ogre::Singleton<TextRenderer>
    ODFrameListener.h:53:        public Ogre::Singleton<ODFrameListener>,
    Gui.h:32:class Gui : public Ogre::Singleton<Gui>
    SoundEffectsHelper.h:18:class SoundEffectsHelper: public Ogre::Singleton<SoundEffectsHelper>
    MusicPlayer.h:21:class MusicPlayer: public Ogre::Singleton<MusicPlayer>
    ODApplication.h:19:class ODApplication : public Ogre::Singleton<ODApplication>
    MiniMap.h:34:class MiniMap : public Ogre::Singleton<MiniMap>
    RenderManager.h:30:class RenderManager: public Ogre::Singleton<RenderManager>
    GameStateManager.h:40:    public Ogre::Singleton<GameStateManager>
    Console.h:37:        public Ogre::Singleton<Console>,
    Director.h:54:    public Ogre::Singleton<Director>{
    ASWrapper.h:24:class ASWrapper : public Ogre::Singleton<ASWrapper>



Well I plan to remove all subclasses "Singleton" . Any remarks welcome ....

Re: removal of Singletons

PostPosted: 05 Jul 2013, 23:40
by domtron
Just to be clear why are we removing Singletons?

Note to anyone who doesn't know the Singleton class is part of OGRE.

Re: removal of Singletons

PostPosted: 06 Jul 2013, 01:32
by Bertram
Yes, why? Please don't only explain what you do, but also why you do it.

It'll help us learn a trick or two, maybe :)

Best regards,

Re: removal of Singletons

PostPosted: 07 Jul 2013, 10:42
by oln

Re: removal of Singletons

PostPosted: 07 Jul 2013, 22:16
by Bertram
Hi oln,

I you look at the answer to this article, you'll see most of those disagree with it.

Singletons are considered a very common design pattern, making possible to smplify a lot the interfaces, and perfectly compatible with unit testing if you add the needed lifecycle unit tests, at least IMHO.

Now, I'm not saying you're wrong at all, but I kinda find the answer too simple. What made you think singletons weren't good in OD in the first place?

Best regards,

Re: removal of Singletons

PostPosted: 07 Jul 2013, 22:59
by Bodsda
paul424 {l Wrote}:Well I plan to remove all subclasses "Singleton" . Any remarks welcome ....

What do you plan on replacing them with?

Re: removal of Singletons

PostPosted: 10 Jul 2013, 10:29
by MCMic
We should make a game out of OD instead of rewriting existing code.

Re: removal of Singletons

PostPosted: 10 Jul 2013, 11:05
by oln
Bertram {l Wrote}:I you look at the answer to this article, you'll see most of those disagree with it.

You can see a more in depth explanation here, why google has banned them from their code:
http://www.youtube.com/watch?v=acjvKJiOvXw

Bertram {l Wrote}:Now, I'm not saying you're wrong at all, but I kinda find the answer too simple. What made you think singletons weren't good in OD in the first place?


A lot of the singleton classes in the code depend on each other, and depends on being initialised in the right order, which makes it hard to change things without the program crashing in hard-to-debug ways. If it was used for a class that was independent from everything else it would be okay, but that is not the case. The reason why I have wanted to do cleanup and refactoring is that it is hard to fix an issue without causing 5 new ones.

Re: removal of Singletons

PostPosted: 10 Jul 2013, 16:47
by domtron
MCMic {l Wrote}:We should make a game out of OD instead of rewriting existing code.


The problem with "just pushing forward" Instead of fix things/doing maintenance like this now is that it will become more and more expensive(as in man hours) to get a new feature implemented. In other words this is important to making a game even if it doesn't seem so from the player/non-programmer view point.

Re: removal of Singletons

PostPosted: 10 Jul 2013, 21:58
by Bertram
Hi,

A lot of the singleton classes in the code depend on each other, and depends on being initialised in the right order, which makes it hard to change things without the program crashing in hard-to-debug ways. If it was used for a class that was independent from everything else it would be okay, but that is not the case. The reason why I have wanted to do cleanup and refactoring is that it is hard to fix an issue without causing 5 new ones.


Ok, I get it. thanks for lighting things up. :)

Re: removal of Singletons

PostPosted: 12 Jul 2013, 03:24
by silnarm
Bodsda {l Wrote}:
paul424 {l Wrote}:Well I plan to remove all subclasses "Singleton" . Any remarks welcome ....

What do you plan on replacing them with?


This.

Needs a good answer.

I'm not familiar with Ogre, but I just checked the docs and Ogre singletons are created (dynamically) on demand, they are not the evil static kind and shouldn't be giving you much grief. What are they to be replaced with, and how will the interdependencies be handled better in the new system?