3 ms·
I sometimes review PRs where people are encouraged (by other reviewers) to create new methods because there's a single line of code duplicated between two other
by barrkel 6y ago
I sometimes review PRs where people are encouraged (by other reviewers) to create new methods because there's a single line of code duplicated between two other methods. I don't think that rate of abstraction construction - and every method is another abstraction - is helpful for the health of the code, or its readability.
- Tainnor 6y agoI can't judge that without more context. If this is just accidental duplication, it's pointless to abstract it away. But if it's a line of code that is necessary to deal with some gotcha of a particular library etc., it's probably good to extract and add an explanatory comment.
- dave_sid 6y ago“Accidental duplication” well said. Not enough people even consider this before deciding that they must remove the duplicate code. Will each duplicate section change for the same reason? If not then it’s not really duplicate code, it just looks the same.
- jiofih 6y agoIf that line of code deals with a particular piece of business logic, that should be consistent within the application, it’s a good thing.