Originally Posted by Terenna
When I saw the difference in readability between arg2 and spellID or what not I saw the importance of naming variables more descriptively. One possible problem with this is that the 12th argument for a swing_damage event is a an amount of damage or a string of miss, block, parry, dodge, etc, whereas the 12th argument for spell_damage is a spellID. To assuage this problem, I could have the first 4 arguments set as they are always the same, and then perform an if check on the 2nd argument to determine type of CLEU event. At that point I could assign variables that would be more accurately and descriptively named, but I would be utilizing extra CPU cycles to perform the check, overwrite the 2nd and 4th arguments unnecessarily and also have extra variables taking up (albeit minuscule) amounts of memory.
|
It's very common to use event-specific functions stored in your frame table and then run them from your event handler. This helps to compartmentalise the code and effectively removes the problem of choosing whether to name your arguments descriptively or not.
Lua Code:
frame:SetScript("OnEvent", function(self, event, ...)
if self[event] then
self[event](self, ...)
end
end)
function frame:PLAYER_ENTERING_WORLD(...)
-- code
end
function frame:PLAYER_REGEN_DISABLED(...)
-- code
end
function frame:COMBAT_LOG_EVENT_UNFILTERED(...)
-- code
end
Any code that is general and applicable to every event can be written directly in the event handler. In the case of processing combat events, you can apply the same principle. In terms of optimisation, there are a couple of things you can do, such as upvalueing the sub table in your color picker instead of doing the table lookup 3 times (one for each color value), but it will hardly make any difference with such a tiny code snippet.