View Single Post
05-02-13, 07:35 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Just a couple things:

1. You're creating a lot of generically named global variables like "ClassTable" and "setContains". Don't do this. Make those variables local instead, or (if they need to be accessed from other addons or via in-game /run commands) at least give them distinct names, like "MyAddonName_ClassTable" and "MyAddonName_SetContains".

Globals are slower to access than locals, and generically named globals have a tendency to overwrite (or be overwritten by) other generacally named globals from other addons or even the default UI. For example, at one point many authors were lazily putting a variable named "_" in the global namespace. Then Blizzard accidentally did the same thing, and suddenly there were hundreds of addons completely breaking parts of the default UI because they were tainting the "_" global.

Also, if users see an error message about "setContains" they won't have any idea what that means, or what's causing it. If they see an error about "MyAddonName_SetContains" they can immediately tell which addon is causing that error, and tell you about the problem.

2. Your "setContains" function in general is completely useless. Instead of if setContains(tbl, "x") then, just do if tbl["x"] then. There's no reason to explicitly check it against nil unless you need to distinguish between nil and false for some reason, and even then, you should just do it directly instead of wasting CPU time on an extra function call. Calling functions is about the slowest thing you can do in Lua, so you should avoid doing it when you don't need to do it.

3. After having said all that, you're not actually using either the "ClassTable" table or the "setContains" function so you should just remove them and clean up any other variables you're not using.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote