“Every line of code is written without reason, maintained out of weakness, and deleted by chance” Jean-Paul Sartre’s Programming in ANSI C.
Every line of code written comes at a price: maintenance. To...
My current project has mostly easy to delete code and not easy to extend. Why? Coz shit was copy-pasted 50 times. It’s not fun to work in this project.
I think the responder means that duplicate code is usually easy to refactor into single methods. Typically I see copy pasted code that is changed just a little bit. However much of a duplicated function can be broken into smaller functions and the redundant code removed in favor of calling into the functions. Often what is left then becomes easier to reason about and refactor accordingly. I love the PRs that I make which delete more code than I add but still manage to add functionality. It doesn’t happen often but it’s fun when it does.
Same thing on my project. Thousands of lines across a few dozen files copied 100+ times. At that point there’s almost no going back with everything diverging so long ago.
TLDR;
My current project has mostly easy to delete code and not easy to extend. Why? Coz shit was copy-pasted 50 times. It’s not fun to work in this project.
I don’t understand, if you’ve got easy to delete copy-pasted code, then delete it. It’ll be a nice and cathartic exercise.
But sounds like what you’re really talking about is code that isn’t easy to delete.
I don’t understand too. Are you suggesting me to drop bunch of features in the product?
I think the responder means that duplicate code is usually easy to refactor into single methods. Typically I see copy pasted code that is changed just a little bit. However much of a duplicated function can be broken into smaller functions and the redundant code removed in favor of calling into the functions. Often what is left then becomes easier to reason about and refactor accordingly. I love the PRs that I make which delete more code than I add but still manage to add functionality. It doesn’t happen often but it’s fun when it does.
Same thing on my project. Thousands of lines across a few dozen files copied 100+ times. At that point there’s almost no going back with everything diverging so long ago.