Back to Top

HAROLD'S BLOG

programming mistakesTOP PROGRAMMING MISTAKES

Beginner programmers may have a tough time trying to discover their own coding errors. Here's a list with the most common programming mistakes.

1. Variable-related mistakes.

Most beginners tend to use lots of global variables. While some are necessary, many of them can be kept local.

Variable names should be clear, consistent and relevant. Don't name a variable "rate_1"; use "yearlyInterestRate" instead.

2. Unformatted code.

Trust me, unformatted code is ugly. The good news is that most Integrated Development Environments (IDEs) will format your code automatically. So, use a decent IDE and start writing clean, nicely formatted code today.

3. Repetitive code.

Don't just copy/paste lines in several functions; put the code that's required in many sections inside a single function, and then call that function anytime you need it.

4. Invalid user input errors.

If your application accepts external input, ensure that the required variables and strings have plenty of space to store all the data. Then, make sure that the input data matches the variable/string type. If the user is supposed to type in a number, the input shouldn't contain any letters or special symbols. If you don't validate the input, cyber criminals will try to exploit this vulnerability, with the goal of getting access to, or deleting the "users" table in your program's database, for example.

Don't forget to handle errors by making use of try/catch exception handlers.

5. Lack of comments.

I know that some programmers prefer to use brief comments, but I strongly recommend that you add as much descriptive text as needed. Yes, you understand what your code does now, but trust me: you're going to have a hard time trying to figure out how that custom data sorting algorithm works in a few months.

6. Hardcoded data.

Yes, it is very convenient to hardcode values, but it is very dangerous to do so. If the password is stored as "my1tough2password3" in the source code, it will be discovered by hackers sooner or later. And when this happens, it will be extremely hard to change it without going through a lot of trouble.

7. Complex functions.

Keep your functions simple. If you decided to write a function, it's probably because it needed to do something specific. If you have new ideas and want to do more stuff, write another simple function. As an example, you should have a function that reads user input, another one which processes it, and a third one that displays it. It's as simple as that, really!

8. Not asking for help.

There are lots of friendly programmers out there! Just search Google for "your programming language forum", and then browse through the first few results (replace "your programming language" with the desired programming language, of course). Then, pick a forum that's active and welcomes newbies. Get involved, help people who know less than you do, and don't be ashamed to ask questions anytime you get stuck.

9. Lack of backups.

Don't allow a minor hardware and/or software failure to destroy weeks or months of hard work. Always keep at least two different backup copies, using different methods. I store all my code using a cloud-based data backup service and two external hard drives; yes, I am that paranoid ;)

10. Not having fun.

I know that you love programming, but this doesn't mean that you should spend the entire day in front of a computer screen. Get involved in outdoor activities as well; most programmers lack the D3 vitamin, which helps normal bone growth and development, increases immunity, etc. Fortunately, the skin produces it in sufficient quantities when exposed to sunlight.