I program in a style that everything it's expensive or I really do hate repeating anything, mostly because I develop for embedded systems. So I get very annoyed when I have to do something that causes repetition.
An example would be that in my current project, I am creating a Layout Manager. I had this huge function that did all the work of placing everything, which I don't mind as long as I comment well. Some point down the line I realise that something I do in that long function I need to do again somewhere else, like adjusting for something that is bigger than the current. But what got me really annoyed ( and why I'm posting ) is that the needed function requires three variables. To me those three variables are expensive and should only be computed once per call. But to refactor the code the way I need to I have to put the variables in the needed function. Now the variables gets evaluated three times.
This is just an example, and things like this crop up a lot else where, so besides telling me those evaluations aren't expensive, at which point I'll say, "I'm still repeating it though", what can be done about this sort of thing, or, to my huge annoyance, is it unavoidable?
Update: One of the main suggestions given is store the value. Using the example above again, storing the value does not seem viable. Mostly because the needed function takes two needed values which are used to compute the three variables. It would mean I would have to create an object, and feel free to correct me if I'm wrong, store the values and variables into the object and then test them if they had changed.
In short, unless there are other ideas out there, it looks to be unavoidable. The only real thing you can do is minimise up to a limit. How deep do I create objects at the cost of property look ups? How many times to I repeatedly have to create those three variables? I hope you get the idea.
There is also the fact maybe I could better refactor my code. I tend to write in huge functions and only pull out what I need, which is probably KISS's fault. I think need another acronym to balance things out :P .