Copying & Pasting is a Harmful Habit

Published: 2018-05-21
Tagged: rants learning programming essay

In my software-developer-for-hire days of the past, I sometimes stumbled upon projects that included copy & paste code. Duplicate code isn't necessarily bad if it helps us avoid the wrong abstractions, but I'm talking about blatant copies down to the typo and style error level. This wasn't a sign of a bad codebase by itself, but it was often accompanied by other problems that made fixing bugs or adding features more labor intensive than it had to be. In many cases, these projects had gone through multiple dev teams, often in other countries, and I imagine the developers, absent from the estimation and pricing process, had to work tight deadlines. Copy and pasting code must have felt like a secret turbo button. Sadly, copy and paste development speeds up both development and technical debt accumulation.

Programming requires focus and deliberation. It's about making numerous small decisions, navigating different levels of abstraction, manipulating small details, all while keeping the big picture in mind. Copying and pasting entails deferring those decisions (and responsibility!) to someone else and ignoring the context you're working in. It's programming by coincidence. It also means working at the wrong level of abstraction — text — instead of object, function, module, or layer. The copied fragment won't match the right level of abstraction or even the problem domain.

Copy and paste is how a lot of developers started their programming adventure. In my case, it was copying chunks of HTML or QBasic from books or websites and hoping that the computer would react in some way. If you ignore how things work, this is a fast way of making things work. Using Rich Hickey's "Simple Made Easy" model, this development mode falls into the "easy" category, which works well for many problems. But definitely not for software projects on which you collaborate with other people, where readability, maintenance, delivery time, and division of labor are topics that can make or break a project.

In short, if you're writing code that other people will work with, copying and pasting should be kept in the darkest corner of your toolbox, used only in very special circumstances.


There aren't any comments here.

Add new comment