When you start something new, you’re inevitably going to make mistakes, this is purely down to inexperience and those mistakes are great teachers in themselves. However, even experts make occasional mishaps. Thing is, to learn from them as best as you can.
There are many pitfalls for the programmer to be aware of, far too many to be listed here. Being able to recognize a mistake and fix it is when you start to move into the more advanced territory and become a better coder.
Everyone makes mistakes, even covers with over thirty years of experience. Learning from these basic, common mistakes help build a better coding foundation.
Let’s take a look into some common coding mistakes
Small Chunks
It would be wonderful to be able to work like Neo from The Matrix Movies. Simply ask, your operator loads it into your memory and you instantly know everything about the subject. Sadly though, we can’t do that. The first major pitfall is someone trying to learn too much, too quickly. So take coding in small pieces and take your time.
Easy Variables
Meaningful naming for variables is a must to eliminate common coding mistakes. Having letters of the alphabet is fine but what happens when the code states there’s a problem with an x variable. It’s not too difficult to name variables lives, money, player1 and so on.
Comments
Use comments. It’s a simple concept but commenting on your code saves so many problems when you next come to look over it. Inserting comment lines helps you quickly sift through the sections of code that are causing problems; also useful if you need to review an older piece of code.
Plan Ahead
While it’s great to wake up one morning and decide to code a classic text adventure, it’s not always practical without a good plan. Small snippets of code can be written without too much thought and planning but longer and more in-depth code requires a good working plan to stick to and help iron out the bugs.
User Error
User input is often a paralyzing mistake in code. For example, when the user is supposed to enter a number for their age and instead, they enter it in letters. Often a user can enter so much into an input that it overflows some internal buffer, thus sending the code crashing. Watch those user inputs and clearly state what’s needed from them.
Backups
Always make a backup of your work, with a secondary backup for any changes you’ve made. Mistakes can be rectified if there’s a good backup in place to revert to for those times when something goes wrong. It’s much easier to start where you left off, rather than starting from the beginning again.
Re-inventing Wheels
You can easily spend days trying to fathom out a section of code to achieve a given result and its frustrating and often time-wasting. While it’s equally rewarding to solve the problem yourself, often the same code is out there on the internet somewhere. Don’t try and reinvent the wheel, look to see if some else has done it first.
Secure Data
If you’re writing code to deal with usernames and passwords, or other such sensitive data, then ensure that the data isn’t in cleartext. Learn how to create a function to encrypt sensitive data, prior to feeding into a routine that can transmit or store it where someone may be able to get to view it.
Math
If your code makes multiple calculations then you need to ensure that the math behind it is sound. There are thousands of instances where programs have offered incorrect data based on poor mathematical coding, which can have disastrous effects depending on what the code is set to do. In short, double check your code equations.
Help
Asking for help is something most of us have struggled with in the past. Will the people we’re asking laugh at us? As I wasting everyone’s time? It’s a common mistake for someone to suffer in silence. However, as long as you ask the question incorrect manner, obey any forum rules and be polite, then your question isn’t silly at all.