logoalt Hacker News

SpyCoder77today at 4:46 PM3 repliesview on HN

I think that this is pretty cool, but is there any reason why we would want to remove similar/possible duplicate code?


Replies

rkochanowskitoday at 6:03 PM

Recently there was a popular article on HN saying that sometimes code duplication is better than abstraction, so I assume that this question is not a joke.

While testing this tool, one detected duplication was interesting for a use case. Permission check logic was duplicated and placed in different distant places in the codebase. The code was similar, but not identical, the logic was not the same. One version had stricter checks. I analyzed this with the coding agent, and we found out that both versions are used for the same thing, which means that in some cases validation is insufficient. Having only a single validation place, this bug could be prevented or easily detected.

rufiustoday at 5:39 PM

(without sarcasm) Is this a serious question?

If so - maintainability, testability. This is old software engineering best practice at this point.

You shouldn’t hyper optimize for deduplication, but it’s usually worth considering. Fewer places to fix issues or improve as well.

show 1 reply
Zopieuxtoday at 5:36 PM

Have you written software before?