Copy, Paste, Repeat? STOP!

The improvement of understanding is for two ends: first, our own increase of knowledge; secondly, to enable us to deliver that knowledge to others.

John Locke

I’ve been programming for over 13 years, 11 professionally. Along the way I’ve learned a lot: both what to do, and perhaps more importantly, what not to do. For this post, we’re going to focus on the latter. I was reading an article on Toptal by Scott Fennell that got me thinking about mistakes that I’ve made. But out of them, the one to follow is perhaps the one I’ve benefited most by learning from.

In the course of a project, we may come across a task where we know there must be a snippet out there somewhere for it. (For this article, we’re assuming all snippets are GPL.) Perhaps we’re on a tight deadline and need to save an hour or two of dev work. Off we go into the great wild world of the Internet. A few minutes later we have our snippet! Copy/paste/test and voila! It works! Great, move on to the next task. Wait! Not so fast. Do you understand the snippet? Can you, for the most part, explain what each line does? If you answered no to either of those questions, we have a problem. Why?

Whatever you cannot understand, you cannot possess.

Johann Wolfgang von Goethe

If not for the snippet you found, you would have needed to write this yourself. So, in order to truly learn, you must understand what the snippet is doing. Perhaps you wouldn’t be able to write this particular snippet from memory after going over it. But, if you can at least see what the other developer had in mind, and the concepts behind it, you’re already a step ahead.

Another benefit is maintainability. The truth is, even helpful snippets may later break. If you don’t understand it, how can you troubleshoot it later? To this I would add the need to leave notes in your code as to where you found the snippet and why it was needed. This will help you or others looking at your code down the road.

Some might say they don’t need to know why something works. However, even for such ones, I recommend it. Truly, the only way to learn is to understand.

Interestingly, there have been studies that show the benefit of explaining a concept to yourself. It’s been found that it improves your capacity to understand and remember it. Try this next time you’ve found a helpful snippet: review it, understand it, and see if you can explain what’s happening. Instead of Copy. Paste. Repeat, let’s try: Copy. Understand. Explain. Paste. Repeat. Now go forth and code!

Leave a Reply

Your email address will not be published. Required fields are marked *