removal of Singletons

removal of Singletons

Postby paul424 » 05 Jul 2013, 22:49

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 ....
User avatar
paul424
OD Moderator
 
Posts: 660
Joined: 24 Jan 2012, 13:54

Re: removal of Singletons

Postby domtron » 05 Jul 2013, 23:40

Just to be clear why are we removing Singletons?

Note to anyone who doesn't know the Singleton class is part of OGRE.
domtron
 
Posts: 101
Joined: 10 Jun 2013, 16:22

Re: removal of Singletons

Postby Bertram » 06 Jul 2013, 01:32

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,
User avatar
Bertram
VT Moderator
 
Posts: 1652
Joined: 09 Nov 2012, 12:26

Re: removal of Singletons

Postby oln » 07 Jul 2013, 10:42

User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: removal of Singletons

Postby Bertram » 07 Jul 2013, 22:16

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,
User avatar
Bertram
VT Moderator
 
Posts: 1652
Joined: 09 Nov 2012, 12:26

Re: removal of Singletons

Postby Bodsda » 07 Jul 2013, 22:59

paul424 {l Wrote}:Well I plan to remove all subclasses "Singleton" . Any remarks welcome ....

What do you plan on replacing them with?
User avatar
Bodsda
OD Moderator
 
Posts: 195
Joined: 18 Feb 2010, 08:19

Re: removal of Singletons

Postby MCMic » 10 Jul 2013, 10:29

We should make a game out of OD instead of rewriting existing code.
User avatar
MCMic
 
Posts: 723
Joined: 05 Jan 2010, 17:40

Re: removal of Singletons

Postby oln » 10 Jul 2013, 11:05

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.
User avatar
oln
 
Posts: 1020
Joined: 26 Oct 2010, 22:16
Location: Norway

Re: removal of Singletons

Postby domtron » 10 Jul 2013, 16:47

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.
domtron
 
Posts: 101
Joined: 10 Jun 2013, 16:22

Re: removal of Singletons

Postby Bertram » 10 Jul 2013, 21:58

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. :)
User avatar
Bertram
VT Moderator
 
Posts: 1652
Joined: 09 Nov 2012, 12:26

Re: removal of Singletons

Postby silnarm » 12 Jul 2013, 03:24

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?
silnarm
 
Posts: 7
Joined: 26 Feb 2010, 04:19

Who is online

Users browsing this forum: No registered users and 1 guest