Sometimes I hesitate between "More code to avoid unnecessary operations" and "less code but with redundant operations". Let me just take an example (Win32 API):
I try to paint some controls manually when the cursor is over it. If the cursor is over this control and it is painted, then it doesn't need to be painted again before the cursor goes out from it.
Of course, I can just paint this control whenever a
WM_MOUSEMOVE appears. Or, I can use more variables to record the state of this control and paint it only when the state is changed.
Although it is not a question (in practice) in my example, I still want to have a feeling for which is the better choice, in general. And if this depends on cases, any way to develop a good sense to do the choice?
(I am not focus on "efficient". It is more or less like a question as: If you are an idealist of programming, which one is better in your opinion.)