in reply to Re: how to make a universally inherited method?
in thread how to make a universally inherited method?

I suspect the better reason for making a singleton, then migrating from it is this:
  1. By forcing everything to use a singleton, you get to mark every place in the code that accesses a global.
  2. In addition, you get to regularize every access of every global, thereby reducing bugs.
  3. In addition(!), you start to find the places that were using typo'ed globals.
Now that the accessing is regularized, you can do a global replace for a single global variable at a time, knowing that you have all your globals code still in one place.

Even if you never go past the singleton, it's still a good idea because you have collected all your globals accessing stuff. I did that in a production project at my previous position and it worked just fine. I had one big Exporter module and each package that needed access to a given global structure would import just that one accessor symbol. I could then grep through the code and find which packages accessed which symbols. This resulted in tighter code and caught about half-a-dozen bugs in the process. :-)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

  • Comment on Re: Re: how to make a universally inherited method?

Replies are listed 'Best First'.
Re: Re: Re: how to make a universally inherited method?
by exphysicist (Sexton) on Nov 30, 2001 at 08:37 UTC
    Hi,

    exphysicist here again.

    I implemented three or four singletons today. It works well and Class::Singleton is a real gem.

    As it happens the globals break down into a number of logically grouped subsets. Each of these sets is well represented by a separate singleton. Not all methods will need to access all of the singletons so my namespace really is reduced. Plus access to the variables can be controlled and monitored.

    There's another issue to consider. As soon as I start moving methods into real classes I break the local variable glue that previously held the program together. Singletons provide an easy and quick way of handling that issue.