2

One of our team member duplicates code. Code duplication causes confusion among my team members reading his code, it causes bugs down the line when the duplicated segment is fixed in one location and not the others and it bloats the size of his code-base.

I have discussed with him not to duplicate code. But he show excuses that it will delay our projects deadline if he refactors all the places where he made code duplication.

How better can I deal with him?

Bjarke Freund-Hansen
  • 1,176
  • 1
  • 11
  • 18
Md Mahbubur Rahman
  • 4,747
  • 5
  • 32
  • 38
  • 1
    Point this person to [Why is “copy and paste” of code dangerous?](http://stackoverflow.com/questions/2490884/why-is-copy-and-paste-of-code-dangerous) – Oded Apr 16 '13 at 13:01
  • @Oded, +1 to your comment. Nice resource. I will point this resource to him. – Md Mahbubur Rahman Apr 16 '13 at 13:03
  • 4
    Almost always the answer to these "inept colleague" questions is global Code Review. – glenatron Apr 16 '13 at 13:11
  • 2
    Changing the behaviour of a team member is *never* easy. Daily code reviews for a long period is the only thing which *may* break bad habits. – Doc Brown Apr 16 '13 at 13:26
  • You're going to find many reasons to give him in the referenced links. If you want to stop hearing the excuse that you mentioned, use static code analysis (specifically, a copy/paste detector). The build can fail immediately when dupe code is present and he can fix before he moves onto something else. – smp7d Apr 16 '13 at 13:40
  • He may be right about missing deadlines if he isn't the one setting the time estimates. And if he is doing his own estimates, tell him to factor in refactoring. – JeffO Apr 16 '13 at 14:19
  • 6
    am I the only one who finds it ironic that this got closed for being a dupe? – ratchet freak Apr 16 '13 at 15:39
  • I think a difference in this question is the poor coder doesn't think there is a viable solution. – JeffO Apr 16 '13 at 19:39

1 Answers1

8

You can explain that it would be more costly in delays to fix the same bug in 5 locations.

And then finding out that the fix was missed in location 6.

It also delays the team when they look at a piece of code, expecting it be be called from one location, but it never does, as it is duplicated elsewhere, where it is being called.

This is particularly problematic when certain versions of the duplication change slightly - it is then difficult to tell which one is the "right" one and why - this is one of the most difficult things to correct and is very time consuming.

You can also send them to Why is “copy and paste” of code dangerous?

Oded
  • 53,326
  • 19
  • 166
  • 181