Usually if you begin with an application you start clean, then it grows to become messy, and then it is maybe refactored back to cleanliness. Here is an intersting idea from Robert Martin:

Always check in your code a little bit cleaner than when you checked it out