I have been working on my hobby project in C++ for more than 2 years. Whenever I write a module/function, I code it with lot of thinking. Now see the problem,do {  --> write the code in module 'X' and test it  --> ... forget for sometime ...  --> revisit the same piece of code (due to some requirement)  --> feel that This isn't written nicely; could have been better} while(true);Here 'X' is any module (be it small/large/medium). I am observing that, this happens no matter how much effort I put while coding. So mostly, I refrain myself from seeing a working code. :)Is this a common feeling for many people ? Is this language specific phenomena ? (Because in C++ one can write the same thing in different ways).What should I do, if I get this re-factoring feeling for a real world production code, where changing the working code will not earn me much accolades but rather it may invite troubles if it fails.
After writing code, why do I feel that I would have written better after some time?
c++;self improvement;refactoring;coding
This phenomenon is very common and not specific to programmers. Whenever you perform an intellectual task, you will notice dozens of places where you could have improved -- after you got some distance. Ask any wise (wo-)man who ever wrote a thesis, and they'll tell you one thing: Don't look at it. You will find an error on the first glance. There are basically two things to avoid the refactoring loop:While writing and designing, try to get the distant perspective as early as possible. Have a colleague look at your design/code. Look again after a weekend. Look at it when drunk or high (but beware: don't change anything until sober).Live with imperfection. If it is merely not pretty, but works well (read: does a good job at fulfilling all requirements, including extensibility and readability), let it stand and be content with the good work you did, not striving for the perfect work.