The same popular metaphor of unit-testing write the test, break it, fix it can be applied at a higher level of abstraction to improve the average quality of your codebase just as you code. Got the point of the code you're going to write? Then write it to see if it fits, ensure it works as it should, fix it and then check-in. Let’s face it! You'd better put any reasonably possible effort in writing code right the first time as you'll never have realistically the time to clean it later. Write your code as if your peers are violent psychopatics that know where you live. Or, more quietly, write your code as a message to the posterity. However, nobody writes code right the first time and any code one second after having been written is legacy code. Aim then at having the classiest legacy code ever.