DEV Community

Cover image for Copying VS Understanding Code
Breeana Payton
Breeana Payton

Posted on

2 2

Copying VS Understanding Code

You need to build a countdown timer for your project. You remember something about setInterval but can't quite place it. You open a tab and see Google staring back. There is a choice here. Do you type "setInterval documentation" or "javascript countdown timer"?

One of these teach you the answer while the other will simply give it to you.

Making Sure You Learn

If you googled the javascript countdown timer one of the first links you'll come across is from Stack Overflow and you'll find a function that looks like this:

function timer(){
    var sec = 30;
    var timer = setInterval(function(){
        document.getElementById('safeTimerDisplay').innerHTML='00:'+sec;
        sec--;
        if (sec < 0) {
            clearInterval(timer);
        }
    }, 1000);
}
Enter fullscreen mode Exit fullscreen mode

When coding for companies or bootcamps there will be a code review and you will have to explain your functions. Here are 3 ways that you can prove that you understand the code and make sure that you're learning:

  1. Can you test the code?

    Looking back on that timer function could you write a test for
    it right now? Which testing library would you use? What would
    a fringe case look like? Do you need any extra resources to
    test it?

  2. Can you apply the code within a framework/other language?

    How do you implement this code within React, Angular, or Vue?
    What does this look like in jQuery or Typescript?

  3. Can you explain this function using comments or documentation?

    This is a crucial skill to have when contributing to larger
    code bases and for debugging. Can you break this code up line
    by line and describe what's happening?

If you can answer most of these questions congrats! You are leveling up. If not, congrats! You have a new goal to chase. I am still building my skills in these areas as all developers are. I'm just letting you know what I wish my bootcamp teachers would have told me. If you need any help with these questions feel free to comment below. I'm here to help.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up