I have a strange question here.
Am I the only programmer here that constantly feels like I must rewrite / refactoring my own codes ?
Sometimes I do it only because I think the speed might be improved, or simply because I believe the code could be easily imported in a later project.
Hey, sometimes only because it looks cleaner for my eyes.
Am I sick ? Am I too perfectionism ? Am I the only one having that problem ?
Take a look at TDD. The basic premise is:
As a general principle I think aggressive refactoring is a good idea - why have any more code than you really need. The difficulty comes in two parts, first, why refactor without a purpose and second, how do you know you haven't functionally changed the refactored code if you don't have a suite of tests against which you can test the refactored version? TDD is an answer to both of those things.
I would encourage you to get in the habit of refactoring, but I would also encourage a practice like TDD so you don't break your code as you do it.
HTH
You are probably just experiencing iterative understanding of the problem. You make a stab for it and then when you are done, you have gained some new insight. This new insight you apply, only to learn that you have a new insight again, so you toss out part of the code and rewrite that.
You should not change code to be faster if you think it is. You should measure through profiling or wall-clock runs. And you should know to what level you need the code improved. Some code need very little speed improvement to be adequate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With