Schedule time to Refactor your code
When I look at code I have written in the past, I usually get one of two feelings. I am in amazement and I am like wow Adim you are a genius, how did you think of this? My code is beautifully formatted, I use smart but clear logic and scanning my code I have full understanding of the system and how I intelligently made it efficient without sacrificing flexibility. Other times I look at the code and I am embarrassed, I see commented out previous code that are useless and I am ashamed off, I see myself hard coding variables that I know I should have calculated programmatically, I see copied and pasted code and sometimes the code is so bad I don't even know what I was trying to do.
This is usually as a result of the philosophy I subscribe to, that you should have working code out to the public as soon as possible and at any cost, and that's the problem right there "at any cost". Like life every decision we make while coding has a cost. It might be time, money, reputation or a whole bunch of other things. I still think this philosophy is solid but understanding that I have to manage my debt is how I stay out of trouble.
The luckiest programmer in the world is she who loses all her code just as she finished the program, the sad truth is that if she retains her sanity, the rewrite will be better, as it is only now she understands the problem - Jo van Schalkwyk
The quote above reminds me of a proverb you might hear in a kung-fu movie. "It is only at the end you understand the beginning", :-) but it is true. Regardless of having deadlines, a well written out requirement document or experience, you can never fully know or prepare for a program you are about to write. There are always parts that were easier than you expected and others that were harder and took longer than planned. Some people find this strangulating because they want to write it right the first time around, I actually find this liberating, knowing I am already doing it wrong allows me to plow ahead and not stress about if it will be perfect in the end because I already know it wont be. The trick here is remembering to come back and make it better.
I'm sorry I wrote you such a long letter; I didn't have time to write a short one. - Blaise Pascal
It is very important to get your idea out there but taking time at the end to refine it, make it more efficient and legible allows your codebase to be sustainable for the future. Code is like art: "Art is never finished, only abandoned" - Leonardo da Vinci