laitimes

Copying and pasting code is likely to have disastrous consequences

Author | Entreprogrammer

Translated by | Sambodhi

Planning | Ling Min

Many people have had the experience of copying and pasting code, but if you often blindly copy and paste code, or even copy and paste code that you don't understand, it is likely to have disastrous consequences.

1

What happens when you copy and paste code that you don't understand

Generate garbage

This is the biggest problem with copy-paste code. Copy-pasted code often contains a lot of extra lines of code that your program doesn't need. If a developer copies it without understanding it, the code becomes complex and difficult to understand.

Poor reusability

The real asset of developing software is not code, but reusable code. So, simply copying code doesn't increase productivity in the long run.

If you find a piece of code and don't understand it, just copy and paste it, then you can't reuse the code correctly because you don't know how it works. Plus, you lose the opportunity to collect reusable code.

Copy the bug

While copying the code, you are also copying the bug. The code snippets you copy can be used in specific contexts, but your problems will be different. So, if you copy the code without understanding it, then you're going to create some bugs that will be temporarily covered up.

Security vulnerabilities

I know of a student who copied and pasted some snippets of code from GitHub into his project because he had to look at the last message his company sent to the user.

He did copy and paste the code snippets, but he didn't understand the code. He ran this code and it worked fine. The problem is that this code can read all the information of the smartphone. This issue has a big impact and can slow down your app.

Introduces a new error

When you paste code in your project, duplicate code can also produce additional errors. Sometimes, it may be that you didn't paste the code in the right place, or it may be that the code you pasted overwrites some of the previous code. If you don't understand the code, there are plenty of ways to copy and paste that can bring disaster.

License issues

Developers often copy and paste code from an open source project. How not to understand the source license implications of copying can be a big problem, especially for embedded devices, where the onboard software is considered a new and unique copy. This isn't something GrammaTech specializes in, but other companies offer these types of analytics tools.

2

Some suggestions

If you're used to copying and pasting code regularly, here are six tips I hope will help you.

Take the time to solve a problem. The more time you spend today, the less time you'll have to spend tomorrow.

Debug copy-and-paste code for better understanding.

Add some useful comments to the copied code so that the QA team can see it better.

Try to break down your code into reusable functions. This will help you understand better.

Before copying from an open source project, look at the license.

Please do not leave any garbage code in the project that you copied and pasted.

Additional Tips:

Some veteran developers have suggested that instead of copying and pasting the code from a website, rewrite it by re-typing in the code. By doing so, you may find something junk or useless and remove it from your code. This will make the code clean and help you understand it better. Another is that it will help you understand the executor step by step.

If we simply copy and paste, we lose these valuable experiences. Believe me, a little effort can turn you from a good developer to a great developer.

3

A few last words

Copying code makes our lives easier. But if we don't understand the code, it won't make us better developers. A great programmer is a programmer who can solve difficult problems when most people can't solve difficult problems.

And a great developer is not created in a day. Solving problems by understanding the code is one of the best ways to improve yourself.

So, while copying and pasting code is tempting, copying code without understanding it is not worth the developer's valuable time. In my opinion, this is self-deception.

About the Author:

Entreprogrammer, a tech entrepreneur and change creator, is passionate about artificial intelligence and blockchain.

https://levelup.gitconnected.com/copy-pasting-code-can-be-devastating-ae1c8252c8fa

Read on