Just getting started as a developer? Trying to avoid the most common mess-ups? Smart move - here are the 12 most common coding mistakes that you should avoid as a software developer.
Vague variable names
Variables are a critical part of programming, irrespective of the language you are using. That’s why you need to form good habits when you’re naming your variables. If you use general terms that seem ambiguous, you could be creating a huge mess for yourself later. Your code would run well, but when you come back to look at your code later, you might find yourself lost trying to figure out what’s going on with your code and what that variable is all about.
And if another developer is working with your or has to maintain your code later, you would definitely be making their life feel like hell by using non-specific variable names.
Repetitive code
If you find yourself repeating your code, you’re going against one of the most basic principles of software development for software developer - DRY (Don’t repeat yourself). You should always aim to follow this principle and write what is known as DRY code.
Any time you catch yourself copying and pasting code, you need to realize that you’re probably detracting from the DRY principle and should check yourself. You can overcome this by using loops and functions. Even web frameworks can be quite useful.
Using an ultra-complicated language
You don’t need to force yourself to code in a language that you don’t understand, just because you see other people using that language. And if you’re coding a custom engine, that’s an extremely bad idea. There are a wide range of beginner-friendly languages that you could find easier to use. Start with one of these and you’ll find it easier to learn other languages once you master this one.
Hopping across languages
Trying to learn multiple languages simultaneously is a horrible idea. You’ll find yourself dazed and confused. It’s also going to be bad if you keep starting one language and switching to another in a couple of weeks. Just pick one language, stick with it, and master it. You can choose to learn another language later after you master the first one, but don’t go on a language-hopping spree.
Crappy formatting
A lot of beginners don’t bother making sure that their formatting is on point because the code could run without errors even if the formatting is messy and inconsistent. But it’s going to be a headache for you to maintain and continue your code in the future… and an even bigger one for another developer if they are tasked with maintaining and continuing your code later on.
Some of the common code formatting mess-ups include:
- Not using proper indentation in your code.
- Using new lines and white space inconsistently or fitting everything into a single line.
- Writing functions that are way too large or squeezing everything in a single line, function or file.
- Using upper and lower case letters in variable names randomly.
This isn’t an exhaustive list of formatting errors in any way. There are many more formatting mistakes that you could make in your code, especially if you are a beginner.
Make sure that you’re writing well-structured code that is clean, readable and maintainable.
No-backups
This is one of the most inexcusable mistakes you could make as a developer, even if you’re a beginner. Imagine that you worked on a project for ages, slogging on it, and then your system crashed and you lost all your work. Even if your seniors excuse you, you’re going to have to deal with the pain of the wasted effort.
You should save your work at regular intervals and keep backups. Use source control (SVN or Git), Github, or even Dropbox to maintain backups of your work.
Over-complicated code
You aren’t trying to prove to the world that you can use the most intricate functions and the most impressive files known to mankind. Your aim, while writing code, should be to solve problems in the most efficient way possible. If your code is simple, it is easier to write, maintain, and manage. Let’s just say that you should follow the KISS (keep it simple, stupid) principle as far as possible.
You got to get to the core of the problem and solve it in the most effective way you can. You could even use pseudocode to do that.
Failing to have a plan
Writing your code without going through the thinking, research, and planning stages of a project is definitely a bad idea. You wouldn’t really understand the problem requirements and limitations, neither would you consider all the case scenarios.
The result? Let’s just say that you could find yourself in quite a mess in the future. Experienced developers no matter the Bubble developer or another generally spend most of their time thinking about, planning, researching, and discussing the entire project and end up spending only about 10% of their time actually writing code.
Fitting too much into a single function
You can use a function for multiple tasks, but that does mean you should do that. Just follow the Single Responsibility principle, according to which a function should only be responsible for doing one thing. If one function is carrying out multiple tasks, you’re practically begging for something to go wrong and negatively impact many other things.
Magic Numbers and String
A magic number is a unique value with an unexplained meaning or several occurrences that should ideally be replaced with named constants. If there’s just a random number somewhere, nobody knows why the number is there and what the number represents.
But if you use a named constant instead, you can see what the number is doing in your code and understand what it represents. It’s also easier for other developers to understand your code and for you to change the value since it is only written in one place and stored in a variable only once. This applies for strings as well.
Hard-coding everything
Hard-coding involves embedding data directly into the source code of a program or other executable objects instead of getting the data from external sources or generating it at run-time.
The issue is that you can’t really configure values that are hard-coded. These are fixed values.
If you tend to hard-code a lot of things, you should take a deep look at your code since most of the time it isn’t the best way for you to solve a problem.
Not using the debugger
If you face a code error that you can’t wrap your head around, don’t waste your time jumping into the code and trying to figure it out yourself. Just use your debugger (most IDEs have them in-built).
The debugger makes it easier for you to solve issues. You’ll be able to see your code run line-by-line, making it possible for you to see exactly what is going wrong with your code.
Here's the top 9 books every Software engineer must check out!