I have an ugly bit of code - essentially iteration over some data structures where the meat of the action was changing, but the iteration code stayed same. The iteration constituted the bulk of code, and there were at least four cases of code copying.
So I refactored the code, putting each level of iteration into its own class (I'll probably do another post on it later).The new code is considerably nicer (at least to my eye), with no copy/paste locations. However, due to some infrastructure I had to introduce to refactor nested loops into separate classes, I ended up with 10% larger number of LOCs. If I discount the extra infrastructure, I get about 5% smaller code compared to the original size.
So, the code is more sophisticated, but it is not shorter and may be harder to understand for a less experinced programmer. I may still end up with shorter code in the future if more oppotunities for reuse present themselves.
My question is: do you think it was worth it? Is it a good idea to refactor for "once and only once" if the LOC count goes up?
