3 things to remember when you’re ctrl+c + ctrl+v-ing

We've all been there. Likely even several times a day. Banging our heads against our keyboards, trying to come up with a solution to any sized problem. Then, we decide to scour the internet to see if others came across the same problem, and voila, the solution is right in front of us!

The problem here is: some of us (especially when starting out), think that's the end. Copy/paste that into our code, and call it a day. But that's not the greatest way to look at it. This solution you've found on StackOverflow, a blog post, documentation, etc, should be thought of as a step in the right direction- not the final destination.

Here are 3 things to remember when you’re copying code from a tutorial/documentation/StackOverflow:

Make sure you understand how, and why, this solution works.

Sure, copying and pasting the solution might solve the issue, but you’re doing a disservice to yourself if you don’t take time to learn what each line is doing! If you don’t, it could cause a debugging nightmare down the line. Break the solution down into smaller chunks, and make sure you come to the conclusion of both how and why it works.

Keep your codebase’s best practices in mind.

This is especially important if you are working as a part of a team. Your team will likely have their own best practice’s/naming conventions you need to follow. Just because an answer to a JavaScript question that was answered in 2006 declares a variable var holder1 does not mean that’s how it should be declared in 2022! Be descriptive in your naming, and please, stick to const or let.

If the solution involves adding an external library to your codebase, research it!

One of the most highly recommended libraries to manipulate dates in tutorials and on StackOverflow is moment.js. But it is actually no longer maintained, and they even advise against using it anymore in their own docs! There are many more reliable alternatives that are still maintained, and they have smaller bundle sizes!

While external libraries often make our lives easier, you should fully trust an external library before adding it to your codebase. There are many factors to consider before you actually introduce them to your code:

  • how much time will you save if you use it VS code it yourself?
  • is the library maintained? When was it last updated?
  • what is the bundle size?
  • are there an abundance of bugs/issues reported (check the library's GitHub Issues!)
  • is it currently being used in a wide variety of projects?

If you've weighed all of these options, and the library still seems like a good fit, use it! Just npm install to your project blindly ;).

Being really, really, ridiculously good at Googling things is the best skill you can develop in this industry! But the idea is that you learn from each thing you needed to Google, so a) you don’t have to look it up next time, or even b) it just clicks for you, to the point you can share that knowledge with others!

Happy coding, fellow devs ✌🏻