S
Searingdeath
Guest
I allways optimize my code if possible easily, and know what? It starts getting cleaner and more maintainable the more I optimize it. Interesting, right?
You're not doing it right then, either that or you're not actually optimizing it but just making it simpler, which would provide those effects.
Optimized code involves locking in certain structures (not structs) within the program and makes them very hard to edit. For example, let's say you're writing a long physics function. It uses lots of real variables, but you realize that after the first half you don't need three of them. In fact you can reuse those variables to save space on your memory footprint (not to mention making it faster since space in memory doesn't need to be allocated). Then you want to add something to the function, later, and you realize that the variables you need are no longer available to you because they've been written over. That's just one example of how optimization can make code harder to maintain.
Another example of optimization is removing functions and placing the code where the function is called. If the function is only called once, then this saves a CALL command (not just in JASS either). For example, take the function:
JASS:
private function getGameCount takes integer selection returns integer
if selection == 4 then
return 5
elseif selection == 5 then
return 15
elseif selection == 6 then
return 40
elseif selection == 7 then
return minigamecount
else
call BJDebugMsg("E:getGameCount(selection = " + I2S(selection) + "): selection out of range.")
return 100
endif
endfunction
That function is only called once in my code, when someone hits a button to select the number of games. I could copy/paste it in there and save on processing time. But then it would be harder to maintain -- the action function for those triggers would be much larger and finding a fault in it would take more time. Another example of how optimization makes things harder to maintain.
Back to your bit of code. Personally, I try to stay away from structs in vJASS unless I need them. Why? Because they generate such convoluted code. It works, but if you have a bug in your code that involves dealing with a struct, it can be much harder to find / fix since the error you're looking for is in the precompiled JASS code.
-- Searingdeath