Copy/Paste

Xerox-boy

Matt used to be an appreciated developer at his previous job, but now he succeeded to join a much bigger software company, one which he and all his friends had always admired. His new colleagues started to trust him also, so he was assigned with creating one new plugin for their application. They were even so nice to show him other plugins’ source code, and explain him how they worked by means of code samples. In one week’s time, he got it all woriking well, but when his code was reviewed, this came out:

/*
* class CGuiSettingsPlugin
* Manages settings for the Graphical User Interface
*/
class CCommunicationSettingsPlugin
{

He is now known as “Xerox-boy”.

As a developer, you are often faced with the situation of creating software components very similar to others, in terms of structure and behaviour. In those times, the easiest approach is to simply copy entire functions, classes, or even source code files and do some changes here-and-there. This habbit, however, has several darker sides which usually strike back sooner or later, one way or another.

Why Copy and Paste? 

Because it’s easy. Why rethink an architecture, why bother to try and convince the managers that the (proper) changes would take more time, why even bother when you can just copy that class, change its name and slightly modify one single member function? It has already worked for you so many times before, so it’s pretty much supposed to work this time too… after all, you are just duplicating something that’s already working.

Because others also did it before you. You are faced with adding a new branch to a decisional “switch”, that already contains 30 other alternative cases. You’re not supposed to change the whole logic right now, are you?

Wrong

Nobody said it was gonna be easy, and after all, it’s not always necessarily supposed to be. There are times in products’ lifecycles when architectures need to be revised, and code needs to be refactored. Postponing those times for too long may force you to eventually do the right thing exactly when you have no time for that.

You may not want to start thinking everything all-over by youself, and it also wouldn’t be advisable, but the least you could do would be to raise the problem, and make people aware of it. There will be for sure many who will understand the need of allocating time and resources for finding the right solutions.

Title picture © Mafoto | Dreamstime.com

  • Facebook
  • Twitter
  • Google Buzz
  • MySpace
  • Yahoo Messenger
  • Google Gmail
  • Yahoo Bookmarks
  • Yahoo Buzz
  • AIM
  • AOL Mail
  • Blogger Post
  • Delicious
  • Digg
  • Google Bookmarks
  • LinkedIn
  • Orkut
  • StumbleUpon
  • Technorati Favorites
  • Windows Live Favorites
  • Share/Bookmark

Tags: ,