Thread: OO initiative.
View Single Post
11-29-05, 04:09 PM   #29
Rowne
A Fallenroot Satyr
 
Rowne's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2005
Posts: 26
It's not only collisions but it's actual pollution that can't be good for the namespace, for exampe -- how do you support saving your variables? The point I would like to make is that flat-global functions are the same as using RegisterForSave(variable) and flat variables.

I used to remember when AddOns did that and in our SavedVariables we'd have this horrible mess, like ...

["MyAddOn_Var1"] = val
["MyAddOn_Var2"] = val
["MyAddOn_Var3"] = val
... and so on ...
["MyAddOn_Var16"] = val
["MyAddOn_Var17"] = val
["MyAddOn_Var18"] = val

Then right below it there would be an entry that is instead ...

Code:
["AnotherAddOn"] = {
   ["Var1"] = val,
   ["Var2"] = val,
   ...
   ["Var18"] = val
}
The principle is the same here, almost everyone switched to tabled SavedVariables because of the awful mess we were creating in their SavedVariables, however, by using flat global functions/variables, we're making the same kind of mess in their memory-space and that can't be good. I'm sure there's a million coding reasons why we should avoid making memory-area messes like that, I'll look it up and try and find a good few valid ones.

Realistically though an AddOn is 'flooding' the namespace when it doesn't need to be. An AddOn coded in OO will only leave one footprint in the namespace, whereas an AddOn coded in flat globals might leave anything up to 100 footprints, or more. This makes the namespace hell to traverse, I'm sure.

In fact, if you do a search on namespace pollution via Google, you'll find that every site that talks about it says that it's a bad thing and that we should avoid dropping loads of global footprints there for one piece of code. Even Programming in Lua, the official book on Lua programming, advises that we not do it.

The only reason I could imagine that everyone would be so steadfastly against pollution is that by polluting the namespace, it'll lead to detrimental effects on the Lua environment. What those are exactly I'd have to research but I wouldn't want to force the issue by finding out through experience.

Summarizing: There's nothing to say that you must use OO but not using OO or at least a tidy tabled system is like leaving hundreds of pairs of unmatched socks and pairs of underwear lying around your bedroom. It has the obviously detrimental aspect of global collision but for it to be unadvisable in such a widespread way (as it is), there has to be more to it than that. Can anyone dig up some resources on this for us?
__________________
There can only be so many ways of doing things; rope rubs against rope and it causes fire, fire cleanses all. Sadly, the ropes can't be around to appreciate it.

Short: Tolerance FTW?
  Reply With Quote