Thread: OO initiative.
View Single Post
11-28-05, 06:16 PM   #18
Legorol
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 79
If you guys don't mind, let me play devil's advocate here a little bit. Does anyone know if there are any performance implications to storing all functions and values in a table, as opposed to in the global namespace? Doesn't this result in two lookups per call instead of one?

I agree that the encapsulated method allows for cleaner code. However, as long as all global functions and variables are prefaced with the AddOn's name (as is the standard practice), isn't the chance of a collision exactly the same as with the encapsulated method?

If one wants performance, does using local functions and variables as opposed to encapsulating in a table gain anything?

In summary, apart from cleaner looking code, I'd like to know what exactly are the advantages/disadvantages of the following three ways of declaring a function:

Code:
function MyAddOn_SomeFunction()
  ..
end
Code:
MyAddOn = {
  function SomeFunction()
    ..
  end
}
Code:
local function SomeFunction()
end
If you are just worried about naming collision, the first two have the same chance of a collision (in my opinion), and the third one is better as it eliminates collision. If you are worried about performance, is the third one the best?
  Reply With Quote