Don’t Copy-and-Paste Code (Unless You Understand It)
We all do it: copy-and-pasting code found on Stack Overflow or a website. Guilty as charged! And that’s OK – there’s nothing wrong with sharing code, and using it to your advantage. There’s one caveat though: you can’t learn from code you don’t understand.
The inspiration for this tutorial came from The Story of The Fraudulent Coder from 2017. An aspiring developer faked their way into a developer job by copying complete projects from GitHub.
That’s a far cry from copying the odd utility function from Stack Overflow, but even that’s beyond the point. Imagine the learning opportunities, growth and experience this developer has missed out on. If only he had completed those projects by hand!
In this tutorial we’ll explore the phenomenon of copy-and-pasting code, and how you can avoid it to become a more self-sufficient coder. Let’s dive in!
Table of Contents
How Copy-and-Pasting Just Happens
Let’s look at a hypothetical scenario. You’re learning how to code and you’re following along with a tutorial to build a game.
The tutorial explains you what you need to do to build a game app. You’re instructed to add a new function to your project, like this one:
extension String Congratulations, you’ve just learned to copy and paste code. You missed out on learning a whole lot of juicy Swift syntax. And you’re learning at a disadvantage now, because next time… you’ll hit that Command + C and Command + V again. Why is it “wrong” to copy-and-paste code? It’s not necessarily wrong from a right-or-wrong standpoint, but rather, one approach to learning code is more effective than the other. You want to use an effective approach, if you want to learn how to code. Copy-and-pasting is a suboptimal way to learn coding. It’s like learning how to become a carpenter by only putting together IKEA furniture. Would you call yourself a chef if all you’ve ever done is put TV dinner in the microwave? You’re not learning anything like that! Let’s take a look at that Swift code sample again: extension String Should you dive deep into each of these topics? You could, of course, but doing so 100% of the time is unreasonable. Your learning progress would grind to a halt, because every bit of code would lead you into an infinite rabbit hole of more new topics. A simpler approach you can take is: You’ve got a shared responsibility with the teacher you’re learning from, that much is true. A tutorial, course or book should explain how the code works, otherwise you might as well copy the entire project as a whole. It’s smart to seek out learning resources and teachers that show you how the code works, and why it’s coded like that. A good learning resource will help you make the code your own. That means you don’t only understand it, but you can also take it apart and assemble it again in a different, functioning way. Differently said, you need to practice and play with the code you’re learning! So far, we’ve discussed how copy-and-pasting code just happens. We’ve also discussed a few alternative approaches you can take. You learn more that way. Can we also define a step-by-step approach that helps you “graduate” from copy-and-pasting code? Let’s see… You can get to work with the above list. Figure out where you are, and try to move up to the next level. For example, if you’re copying large parts of code, see if you can learn to adjust the code to fit your own needs. This list isn’t intended to categorize developers based on their skills. It’s more of a guideline you can use to get better. It’s up to you whether you use it or not, and how. In these levels of copying code you can see two recurring themes: the amount of code you figure out on your own, and the amount of code you copy-and-paste. You’re a more productive developer if you write code yourself, as opposed to copy-and-pasting the code. You also build your ability to read and interpret code, which is a valuable skill. You don’t need a brain that can “compile” code, but you do need to be able to understand the mechanics and key points of a code sample. †: “Stealing” here comes from Pablo Picasso’s quote “Good artists copy, great artists steal.” You can explain that quote in different ways. Focus on the quote’s stealing; if you steal something, you make it your own. It’s not someone else’s code anymore if you’ve rewritten it, made innovations, and made it entirely your own. Copy-and-pasting code you found on the internet into your own app is inevitable if you’re starting out as a beginner software developer. You don’t, however, have to keep doing it just because you once started with it. It’s a suboptimal way to learn more about programming! You miss out on so much experience, growth, and excitement.
{
static func randomNumber(length: Int) -> String
{
return Array(0..Don’t Miss Out On Experience & Growth
{
static func randomNumber(length: Int) -> String
{
return Array(0..How To Get Better At Coding
Conclusion
Related Articles
Most Popular Posts
How Marketing Automation Can Grow Your Business?
By Abhinav Girdhar | October 18, 2020
9 Ways to Drive Traffic from Facebook to Your App
By Abhinav Girdhar | April 16, 2018
Why the Education Industry Should Start Leveraging Knowledge Bases?
By Abhinav Girdhar | June 16, 2020
How To Make Your Small Business Cybersecure? [10 Awesome Tips]
By Abhinav Girdhar | October 10, 2018
- How To: Get Started With CocoaPods
By Aasif Khan | December 29, 2021