Correct Speling

Correct Speling

Photo by Cam Fattahi on Unsplash

Isn’t that misspelling in the title just grating? It feels like whoever wrote it didn’t care, right? 

How about variable eror_code, class BankTarnsaction or function AddCusomer()? It looks like somebody didn’t care here either. 

Sure, we are all human and make mistakes. I’m happy to admit that I make many. I understand that some developers might be dyslexic or have English as their second language. Fair enough. However, anyone else who comes across these errors and does not fix them does not get off so lightly in my book.

It’s OK to make mistakes; it’s not OK to not fix them. 

When we see a misspelling in code, we should fix it asap.

The computer doesn’t care how variables, classes or functions are spelt. But humans do. Incorrect spelling subtly signals to readers that ‘The writers of this code don’t care about their work’. It’s human psychology. We can consider misspelling part of the ‘broken window’ theory applied to programming. 

The broken window theory suggests that shattered windows on a building, when left unrepaired, will cause vandals to break more windows within a short time. A few smashed windows signal a state of neglect and decay, inviting the throwing in of more windows. 

In our codebases, we want to avoid a comparable situation like the plague. ‘Nobody cares about this code, so why should you?‘ is the wrong signal. We want the opposite. We need the code to look its best so that our motivation to keep it great stays high. We want to be proud of what we have achieved. And we want others to care about the code too.

One reason why working on legacy code can be psychologically challenging is that it’s like installing a new window in a dilapidated and abandoned building. It feels pointless; nobody is going to notice our work. It feels like a drop in a bucket, so why bother?

OK, I have droned on enough about the psychology of fixing spelling errors. What does it mean in detail?

Comments

I like to fix spelling errors in comments as soon as I spot them. Comments are inert and not part of the program. Fixing spelling errors should be safe.

Code

Misspellings here are a little trickier. When I cannot correct the spelling inside a few minutes, I might make a note to myself to do it later or even put it as a task on the backlog. The advantage of putting it on the backlog is to show to the team that fixing spelling mistakes ought to be taken seriously. The downside is that it feels a little like make-work.

Using the Rename feature of an automated refactoring tool, like Resharper, makes this task a snap. In statically typed languages, even manual renamings are pretty safe as the compiler will complain and point out missed renamings. In dynamically typed languages, we are not so lucky, although a language-aware editor can point out mistakes in renaming. A suite of unit tests is invaluable.

So, the recommendation is not to leave misspellings but fix them as soon as possible.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply