I've been toying with my first add-on, a bandage/potion/food/drink chooser, and had a question about function efficiency. (BestInShow on the SVN. Warning, it's scary to look at right now.)
Tekkub tossed up 'PotHead' on the SVN, in which every item type has it's own function. I've been building on the concept that, as the process is the mostly the same, it can be a single function. However, that leaves me with conditionals as I sort out the differences. (Bandages can be applied to target, some items check health, others mana, etc.)
In the interest of making things as tight as possible, are there good guidlines on where someone should draw the line when it comes to conditionals versus seperate functions?
I personally find if you're doing the exact same thing over and over again, yea use one function. If each different instance is different enough go for seperate functions. In pothead each different item type was different enough logic that I decided to go the route of seperate functions. It also made more sense to me that way because I was making the functions with the intent of them being used in macros, just seemed more logical that way.
Perhaps you should split the logic out into seperate functions? grab the values you need (mp or hp, etc) and then feed those and the set into the function, it would return back the best item. Then perhaps another function to apply the item, it'd take a true/nil arg too know if it should use self-only or friendly-target logic. Just a thought :)
To me.. pickAndUseBandage() is the same as pickAndUse(bandage), but I can see your point of view on that.
Breaking it up by process might help as well. Really, the only main one is target or no target. Everything checks /something/ (which I have stashed in another subroutine anyway.)... ooo.. unless i want to add buff-food.. and check to see if it has that buff already.. hrm... something to consider.
Right.. I was just thinking about that. The failovers are going to get me if I don't prep for them now. Things like battle-ground specific food/bandages, or conjured items. There are a few ideas that I'll play with, maybe I'll end up with one I like.