5 Common Coding Mistakes And How to Avoid Them
Rachel James
October 9, 2019 2 mins

Every coder makes mistakes. It’s the only way you can improve your craft. However, learning from these mistakes is the crucial step towards improvement. If you make the same mistakes again and again, then you have a problem. This article will discuss the most common technical and practical coding errors and how you can best avoid them.

Mistake #1: Working on your most difficult task last

It’s easy to understand why people procrastinate when writing code, especially when you have a difficult task on your plate. However, putting off writing difficult code and starting with easier tasks is one of the worst ways to go about it. You’re more prone to making mistakes at the most crucial steps. Codeslaw recommends doing the difficult tasks at the start of the day, then working on less strenuous tasks as the day goes on. This way, you’ll find that you make less errors and you feel freer as a result.

Mistake #2: Syntax errors and typos

Most of our coding mistakes come from syntax errors and typos. This may be due to various reasons, but most of them stem from these two: you’re writing code too fast, or you don’t have enough practice. You might feel pressured to produce high-quality code at the shortest time frame possible, but don’t let it get to your head. Writing good code requires intense focus and patience. Remember that it’s perfectly okay to reduce your coding pace especially if this helps you deliver error-free code in the process. Another way to avoid syntax errors is good old practice. The harsh truth about programming is that errors are unavoidable, but dedicating time to practice helps you get there. Participating in coding challenges like Coderbyte or HackerRank are great ways to practice and enhance your coding skills.

Mistake #3: Not checking for bugs

Some coders write multiple pages of code before testing whether their code works or not. By the time they do check it out, they won’t know where their bugs are located. It’s important to test your code every so often to have error-free code. It’s a safe and cautious way to go about it, but at least you’re sure you won’t get into any costly mistakes. The Facebook cybersecurity incident last 2018 was due to vulnerabilities caused by multiple bugs acting together that granted users permission over others’ accounts. Bugs can lead to detrimental security vulnerabilities such as these, and checking your code often is the only way to avoid them.

Mistake #4: Broken or risky cryptographic algorithm

An article on ‘Common Programming Coding Mistakes’ by Make Use Of suggests that cryptography is constantly evolving. What may be acceptable today may no longer be tomorrow. Having broken or risky algorithms can lead to cybersecurity vulnerabilities. Thus, it’s important to keep up to date with the developments in cryptography and update your code if any vulnerabilities or hacks are discovered in the algorithms you use. Furthermore, the ‘Cybersecurity Basics’ post by Marcus reminds us to keep our software systems up to date and back up our data regularly. Having outdated software may leave your application open to attack.

Mistake #5: Allocating resources without limits

Memory allocation is common for those using C and C++ as memory management is done manually. However, when you allocate memory without proper validation of the size to be allocated, this can cause failures. When the result of the allocation isn’t checked, this can lead to disaster. This error can also arise when creating other resources like file or connection handles. Not closing the resources properly when you’re done with them is the easiest way for the resource limits to be reached.