Quantcast
WoWInterface - View Single Post - Critique my code!
View Single Post
08-21-19, 12:57 PM   #5
Lybrial
A Warpwood Thunder Caller
AddOn Compiler - Click to view compilations
Join Date: Jan 2010
Posts: 91
He is basically saying that an integer loop is faster than ipairs. But... to be honest...
that really does not matter. You are not doing any stuff which needs a optimized
performance. Your code is fine. The only thing I would criticize is that you are not
covering every minimap button, only those in your table. You could do something like this
to get every button:

Lua Code:
  1. local excluded = {};
  2. local buttons = {};
  3.  
  4. local function initButtons()
  5.     for _, frame in pairs({ Minimap, MinimapBackdrop }) do
  6.         local children = frame:GetNumChildren();
  7.  
  8.         for i = 1, children do
  9.             local button = select(i, frame:GetChildren());
  10.  
  11.             if (isValidButton(button) then
  12.                 tinsert(self.buttons, button);
  13.             end
  14.         end
  15.     end
  16. end
  17.  
  18. -- validation could be something like:
  19. local function isValidButton(button)
  20.     if (not button) then
  21.         return false;
  22.     end
  23.  
  24.     if (not button:IsVisible()) then
  25.         return false;
  26.     end
  27.  
  28.     if (not button:GetName()) then
  29.         return false;
  30.     end
  31.  
  32.     if (not (button:GetWidth() > 14 and button:GetWidth() < 55)) then
  33.         return false;
  34.     end -- questionable restriction
  35.  
  36.     if (not (button:IsObjectType("Button") or button:IsObjectType("Frame"))) then
  37.         return false;
  38.     end
  39.  
  40.     -- exclude those buttons, which are in the excluded list
  41.     for _, value in pairs(excluded) do
  42.         if (string.find(button:GetName(), value)) then
  43.             return false;
  44.         end
  45.     end
  46.  
  47.     return true;
  48. end

In general I would always recommend to choose speaking variables and function names.
Also I would recommend anyone who starts to code in any programming language to
get to know the basic programming and engineering skills.

Originally Posted by fusionpit View Post
It'll probably be hard, because the two hardest things in software development are regular expressions, naming things, and off-by-one errors.
THIS!

Last edited by Lybrial : 08-21-19 at 01:01 PM.
  Reply With Quote