3 ms·
I'll agree that they are often a very bad idea. But there are advantaages: 1) Writing the same code a second time often results in cleaner, more efficient co
by wccrawford 15y ago
I'll agree that they are often a very bad idea. But there are advantaages:
1) Writing the same code a second time often results in cleaner, more efficient code that is easier to maintain. If you don't believe this, write a small app. Then start from scratch and write the same app again, from scratch, without looking at the other. For further proof, do it again.
2) Some code is just not maintainable. If you can't test it, you can't change it without fear of breaking something. I usually do my best to write tests for the old code, but sometimes that's just not possible.
3) Feature creep. That old code was designed to solve an old problem, and then modified many times to solve newer problems. There are a ton of features and quirks that aren't useful any more, but nobody removed them. If you tell a PHB "I'm going to remove a feature" they will freak out. If you tell them, "That feature didn't make it into the rewrite because it's not used enough" they will thank you for saving the company money. (Bosses that get it are different, but this tactic is still more palatable.)
- DrJ 15y ago1) This is true for YOU not necessarily for the next person, hopefully when you are rewriting the code you maintain some level of decency and leave a comment trail. If you optimize and clean the code there is a high chance that you end up with complex functionality packed into one liners. 2,3) If you do not have a test suite how can you reproduce the original code 1 for 1? Similar for new features. I totally agree that code (at least functionally) should always come with a test suite. If there isn't a test suite and you are planning to rewrite the code, the priority should be in writing a test suite or a black-box tester. At the minimum you should have a list of supported features that you are going to check off.