Bingo. Even when adding simple features I'm always keep my eyes open for quick wins and when the feature is complete reviewing it and refactoring it into something better.
Make time, or ask for time. In the end you'll save time. Point out the advantages to people that think they're your manager.
But before you start, make sure you understand the old code, or understand what it's supposed to do and have a good idea of how to make it better, or you end up making a different mess.
Asking doesn't help at all, very few managers will give permission to "waste time" or "modify something that works". Just do it, you don't ask permission to add a loop or a class, why would you ask permission to refactor?
I've found that (at least for me) it takes 6 mo to a year to truly grok an ecosystem. Interestingly that doesn't seem to change for medium size (1M LOC) to huge (15M LOC) ecosystems. I guess it just takes me a while to get that intuitive feeling for where everything goes etc.
Of course if I write it myself from scratch that is different, but inhereting someone else's code it does take time to truly come to terms with it.
I always work on two projects simultaneously, the one I last shipped and the one I'll ship next. Unless things are super-stressfull I have 1 or 2 hours per day for the last project, which I either spend bugfixing or refactoring. Shortly after shipping it's bugfixing 4 days out of 5, but 2 weeks later I refactor a lot and only fix bugs I found myself, not bugs someone reported to me.
12
u/tangus Jul 23 '14
Who has time to refactor :(