Newbies: Code not working? Check the spelling!

Attention newbies: Spelling errors can derail your code, cause profound anxiety, and possibly crush your spirit! You may have heard this, and done this, but keep it close to your heart and on your mind because it happens (a lot).

How do I know this? I just did it. And I'll do it again. When I started coding, my tendency was to assume I completely misunderstood the code instead of diligently combing through code to figure out what small error--likely spelling--was causing the problem. This kind of thinking is rooted in "imposter syndrome" and the human tendency to doubt oneself.

Don't do that. Instead, take a deep breath and question your spelling. In the past week alone my code was seriously derailed, as in stopped dead in its tracks, twice by one misplaced letter.

Today's blunder happened when I was formulating response headers for a new server I created. I'm doing a little project where I am building a simple blog application. The code looked right:

const http = require('http');

const server = http.createServer((req, res) => {
    console.log(req.url, req.method);

    res.setHeader('Content-Type', 'test/plain');

    res.write('hello there!');
    res.end();
});

server.listen(3000, 'localhost', () => {
    console.log('listening for requests on port 3000')
});

Can you spot the error? It took me about ten minutes, which is a vast improvement over the other one this week that took me over an hour of hair pulling and teeth-grinding angst. All over one letter.

My code does not have a soul. It just follows instructions, so if there's a problem I am telling it to do something it doesn't understand. Therein lies the error. When my code is not working, I am really starting to look at the words. I ask myself these questions:

  1. What am I trying to do?
  2. Does what I wrote actually do that?

If I can't identify my problem with the two questions above: I check my spelling. Chances are, it's just one letter.

I have to keep reminding myself: I understand this, I probably just made a simple mistake. I try not to let those little spelling errors make me question my progress and my understanding of the code I am writing.

In fact, catching these errors is a small victory and it builds confidence in my ability. I never knew that coding was going to make me a better editor!

 
Share this