DEV Community

Daniel Med
Daniel Med

Posted on

copy and paste , with or against

So i think most of developers don't write code from scratch any more , actually they edit it.
each time i start a new project i find myself taking codes from different resources and bind them together to come up with the final result,i consider this as a short cut , it saves me a lot of time and energy , especially if one of the tasks is not that hard and does not require a huge effort . so do you think this a code habit or i should change it ?

Top comments (6)

Collapse
 
visum profile image
Benjamin

I don't think asking "is copy/paste good or bad?" is quite the right question. The question is, "do I understand what my code is doing?" As soon as you put code into your project, whether you wrote it or grabbed it from Stack Overflow, you are responsible for it. If you have no idea what

eval(atob("ZGVzdHJveUFsbFRoZVRoaW5ncygp"))

does and you use it anyway, you are being irresponsible and the only thing you'll learn is that you can't trust everyone on the Internet.

However, if you are using SO as a way to learn what you don't know, and you take the time to understand what the answers actually mean, it can be a great tool. Often the answers won't fit your need directly, and you'll end up rewriting them a little bit to fit. You can't do that if you don't know how they work.

In other words, the shortcut that you're taking shouldn't be to just get the job done faster (though that will happen). You are going to avoid some time beating your head on the desk, not knowing where to start with some problem. There is a lot of experience on the Internet that you can use to kick-start and supplement your own experience - use it!

Collapse
 
peterj profile image
Peter Jausovec

Create react app comes to mind; it's a great tool to help you get started, there's probably a lot of boilerplate code that you don't want to write from scratch anyway. In that case, I don't see a problem with copy/pasting something, especially if it gets you up and running faster.

Collapse
 
dylanesque profile image
Michael Caveney

This is a bad habit. Unless it's something really basic, like boilerplate HTML or filler text, copying code robs you of deliberate practice of constructing logic from scratch, and the process of taking the steps of solving a problem.

But...

I think it's ok from time to time provided that you take the time to learn and deeply understand what the copied code is doing. The last thing you want to do as a developer is pick up habits that erode your ability to work through a problem step by step, especially when it's difficult.

Collapse
 
ali profile image
Daniel Med

Writing a code without understanding what it does is not something that I can let my self do it , the point is that we often found a task in a project that has nothing new to us , for example BREAD operations , if a developer tooks too much time making it , it won't be so benefit .

Collapse
 
georgecoldham profile image
George

It depends, if it is for a personal project or to learn then it is fine. If you are working for an employer/client, then if you are going to, you should understand what it does and why.

As for using boilerplates when starting new projects, as long as you understand why you are using it and understand how to make it fit your needs then again, no issues.

Collapse
 
molly profile image
Molly Struve (she/her)

For it!!!! Like many things, if you do it responsibly it can be hugely helpful for your productivity.