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.
Give him a copy of Refactoring.
If he is superior (or supervisor) to you, ask more explanations - its possible to know more about the context... maybe doesnt worth to refactor the code (maybe is a small project).
If he is equal to you, you can report to your superior, by proposing this solution (which is a better one).
If you are superior to him, just "ask" him to do your way...
Ask him what will he do when he finds a bug in his code. How many places will he now need to fix it in?
You can also show him the answers to this question (Why is “copy and paste” of code dangerous?).
Appeal to your boss on technical grounds. If the boss agrees with your colleague's methods/and/or doesn't make him fix it, then there aint much you can do if appealing to reason doesn't work.
First, acknowledge that he's right: copy-paste is indeed faster now.
Then, say that the problem is the cost in the long run, and that the cost will increase because with duplication, the system isn't as well-ordered as it could be. He's introducing disorder, clutter, and the more disorder you have, the harder it is to work with a system. Applying some effort now to organize it better will (usually) pay off in the long term. It's just like keeping your desk or room organized.
This is Ivar Jakobson's idea of software entropy
Tell him that you never know where an application can go in a business... A simple test application can sometimes get modified over and over, and finally end up being used a lot... I've seen this often in small companies. And then, instead of starting everyting over and waste time on things that could have been fixed before, you could simply do it now, short and sweet, while it can be...