A global namespace as an object is all you need for managing global
variables.

...as long as you don't want compile-time type checking, the ability to watch one of them or fire an event from them *ever*, and so on and so forth. Oh, wait... I get it now! *You're* that guy whose project I inherited with this line found mysteriously in it:

_global.dog = "bone";

   If you're that guy, I hate you.

If you have variables that need complicated watching and events then putting
them in a global namespace is the wrong place for them because they're
obviously more specialized and belong in a class that is meant for managing what those variables are about, thereby nullifying the reason to put them in a global namespace. Technically, any variable in any class is, in effect, a variable in a global namespace. That doesn't mean you should write a class for storing globals. It's an extra layer of abstraction that only serves to
complicate something that is straightforward and simple.

Unless you keep it straightforward and simple and only complicate it when necessary...

I never said OOP is job security.  I never said OOP is complicated.

   Someone did... and he looked suspiciously like you.

You don't need to put everything in a class or
component to code OOP correctly.  There is such a thing
as taking OOP too far.

Well, if your entry point is the constructor of a class, then, technically, yeah, everything is in a class. I think what you mean is that it is possible to take *abstraction* too far, and I agree. Making a globals class that only allows objects that implement the globalvariable interface and inherit from the globalistic class would be taking it too far. Putting a class between your code and *any* kind of data is just a good idea, and that goes for databases, web services, and yes, global or session variables too. It allows the (absolutely necessary) validation that eliminates headaches later.

I mean, the fact that you need a class to manage your globals because it
makes it easier for debugging is telling. How overcomplicated is your code
that it is so buggy that you need a class just to debug your global
variables?

Depends on how many people are working on the project and how many different people will be setting those global values, and if I can count on them to set them to a predictable type, and if I need to know when they get set, and ...

ryanm
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to