The most common coding errors

No matter your skill level or experience, anyone that writes and deals with computer code will experience coding errors, from time to time.

Coding errors could take the form of typos, flawed logic, or an accidental oversight. And how they manifest and impact the program determines which type of error they are.

So, here’s a refresher course of the main types of coding errors.

Syntax error

A syntax error is akin to a spelling error, grammar error or basic typo. It’s where the code has been typed incorrectly.

Humans can (and do) communicate without perfect grammar, punctuation and spelling. We can work out what the other person meant and ignore these niggly little mistakes. Computers (for the most part) cannot ignore mistakes as we can. They can’t tell what is or isn’t supposed to be there. As such, syntax errors trip them up. 

Missing semicolons, extra brackets, misspelt instructions, and misplaced capitals are all examples of a syntax coding error.

Syntax errors are among the easiest to find and fix. This is because your compiler will often give you the location of the error.

Runtime error

Runtime errors (also known as execution errors) are coding errors that show themselves when you or a user tries to run your program. Essentially, a runtime coding error is when something has confused the computer and caused it to crash.

For example, your instructions could be in the wrong order, relying on a step that hasn’t happened yet. Or, you might have asked the computer to do something impossible. (A common example here is asking a computer to divide by zero.) Another reason a runtime error could happen is if the user has interacted with a program in an unforeseen way.

Run-time errors are a type of error that can impact your users, preventing them from achieving what they want from your software. You find them by encountering them, so making sure you test thoroughly. A good technical support/bug report system always helps, too.

Logic error

The hardest type of coding error to locate and fix is the logic error. With logic errors, there are no crashes or helpful highlighting to point out the problem. Instead, the program runs successfully. But it doesn’t do what you wanted it to do.

Programs with a logic error don’t behave as desired because you’ve programmed it to do the wrong thing. For this reason, logic errors make everything look like it’s working, because it is. It’s written in a viable language and is an executable program.

This means that you’ll notice there’s a logic error based on the behaviour of the program, and the output it generates. Fixing a logic error can mean tweaking your code or rewriting several lines of it.

Types of coding errors

There are other categories of coding error if you look for them, but these are the main three.

Every developer, young, old, new, experienced, will encounter coding errors — and make them, too. It’s part and parcel of the job. But the more code you write, the better you get at spotting them and fixing them.

Nobody is perfect. That’s why we have debugging practices.

Useful links

The myth of the clean code base

What is technical debt and what should you do about it?

The positives of negative code