How to convince a colleague that code duplication

2019-03-09 12:08发布

A colleague of mine was implementing a new feature in a project we work on together and he did it by taking a file containing the implementation of a similar feature from the same project, creating a copy of it renaming all the global declarations and slightly modifying the implementation. So we ended up with two large files that are almost identical apart from renaming.

I tried to explain that it makes our project more difficult to maintain but he doesn't want to change anything saying that it is easier for him to program in such way and that there is no reason to fix the code if it "ain't broke".

How can I convince him that such code duplication is a bad thing?

It is related to this questions, but I am more interested in the answers targeted to a technical person (another programmer), for example a reference to an authoritative source like a book would be great. I have already tried simple arguments and haven't succeeded.

14条回答
萌系小妹纸
2楼-- · 2019-03-09 13:05

There are lots of valid reasons not to duplicate the code, but just ask... does your team want to maintain 100K lines of code (with code duplications), or 50K lines of code? It may seem code duplication at this point is minimal, which is why your coworker doesn't see the importance of DRY concept, but imagine if s/he duplicates more and more code for the next 5 years. Who is going to maintain that code? Your team? What if s/he leaves the job one day? Do your team want to maintain this crap? :) If not, then you already made a very compelling case not to duplicate the code, not to mention "more duplications" = "more prone to having more bugs in the future".

查看更多
beautiful°
3楼-- · 2019-03-09 13:10

Improve your version of the code so much that he is frustrated with jealousy, then say - if you had just linked to my code...

查看更多
登录 后发表回答