Skip to content
loading...

Do You Copy And Paste Code?

Milecia McG on November 29, 2018

You'll be hard pressed to find a developer alive that hasn't copied and pasted code at some point. It might be code from an old project or a snippe... [Read Full]
markdown guide
 
 

I do that all the time! 😸 I create my websites with an emphasis on accessibility. They all have colored themes that can make the site easier to use for people who are colorblind. The themes are also reversible to accommodate people who need light-on-dark contrast instead of dark text on a light background. 😸

 

I'm personally on board with copying and pasting code with the caveat that you understand it. You could even argue that it's not a huge jump from that to using an OSS dependency. I mean, in both cases you're using someone else's code to accomplish something in your project. In both cases, if you don't understand the code you're using, you're opening yourself up to issues like incompatibility or malicious behavior (like the recent event-stream fiasco).

Reading other people's code is a great way to learn. Including unvetted and not-understood code is asking for trouble, imo.

 

Here's a trick I learned. Instead of straight copying and pasting the snippet, type it all out. You'll be much more likely to understand the code this way. If there's something you don't understand, pause and find out why it works. Don't just copy pasta. If you find yourself using the same snippet over and over, put it in a function or method call. But please, don't just copy pasta, meatballs and everything.

 

Copy Pasta... This is one new Pasta flavor and seems to be an interesting one

 

Typing it out really does help. Sometimes that's how I figure out what the code is actually doing. But you're right. It's usually never a good idea to just copy pasta. 🙂

 

The worst projects I've worked on are the ones where I'm required to copy and paste someone else's code with trivial modifications. It's demoralizing and depressing. Once in an emergency I can handle. But as a practice, if someone wants code copied and pasted they should find someone who doesn't care about writing their own code.

 

How do you feel about using copied code?

I've seen in code comment with just a link to StackOverflow(SO hereafter). When asked why the code was used, the dev didn't know how it worked.

But I could not bring that in a meeting because I was guilty of doing the same, also causing a bug and hindering the bug fix (as I had to understand the code first).

So I "feel" that it's quite bad practice because one might need to change the copy-pasted code not because of a bug but also due to a business logic change. It'd slow down the person who used the code without knowing but also others who have to take it over.

 

Hi!
I come from sys-admin and I'm starting to get more deeply involved in the developer world and I'm fascinated by how many people contribute their repositories or code examples to help others. I just think that copying and pasting code is very useful to understand how a language works and to gain fluency programming.
Other hand, reading a lot of documentation in English its help to me to improve my English hahahaha

code of conduct - report abuse