View Single Post
03-17-12, 07:42 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The most efficient code isn't always the most readable code, so if you find a particular construct difficult to read and understand, you might choose to use code that's slightly slower or uses slightly more memory to make the code easier for you to write and maintain.

Generally, the difference between things like:
Code:
for i, v in ipairs(tbl) do
    -- do something with v
end
vs
Code:
for i = 1, #tbl do
    local v = tbl[i]
    -- do something with v
end
or
Code:
table.insert(tbl, "lolcats")
vs
Code:
tbl[#tbl+1] = "lolcats"
is too insignificant to be noticed in actual usage, so you should use whichever is easier for you to work with.

The exception would be if you're using it somewhere where speed really matters, like inside an OnUpdate script or in response to an event that fires very frequently like COMBAT_LOG_EVENT_UNFILTERED; in these kinds of places, you should always use the faster code.
  Reply With Quote