10 Most Common Programming and Coding Mistakes
Programming is all about working smart and finding effective ways to build useful software. Whether you’re creating software programs, web apps or mobile apps the principles of programming remain the same.
When first learning to code it’s important to understand good habits and bad habits. Knowing mistakes coders make, and how to avoid them, can help you build a better foundation in your programming. Here are 10 very common mistakes to avoid.
1. Repetitive Code
Don’t Repeat Yourself is one of the basic principles of programming that you will come across as you learn. This is often shortened to DRY, and code that is written using this principle is called DRY code.
Repeating code is an easy trap to fall into, and often takes some review to understand just how much code is repeated. As a good rule of thumb, if you’re copying and pasting code it’s probably repetitive and should be changed.
Get comfortable using loops and functions to do your work for you and this problem will go away. A web framework can also help you cut down on repetitive code. Here are a few web frameworks worth learning as a developer .
2. Bad Variable Names
Variables are essential in programming no matter which language you’re working in. Because they are so widely used, it’s important to have good habits naming variables.
Variables should be named accurately and neatly. Avoid using general terms that don’t mean anything. It’s quick and easy to throw something together, but when you need to come back to your code later it makes it much more difficult to figure out what is going on.
Let’s say you’re writing a program that uses an interest rate to make a calculation. You write a variable to use in the program.
let rate = 0.1;
All we really know about this variable is that it’s a rate. What kind of rate?
The code will work just fine, but it’s hard to tell what is going on here.
Instead, name your variables more clearly.
let interestRate = 0.1;
3. Not Using Comments
Use comments! Comments are the documentation of your code. They’re the best way to describe what exactly is happening in your code as it grows. Sure, it seems a little bit more work to explain your code but you will be thanking yourself later.
Write a brilliant function? Write a comment about what it does. Creating a new object template for Object-Oriented Programming? Break it down with a comment. Comments are used in every language, and they are there for a reason.
Comments make your code cleaner, easier to navigate and make you the hero to the next developer that may need to work on your project.
4. Language Overload
A problem that seems to overload growing developers is the barrage of new languages and technologies. Online developer communities are full of questions about language choices.
Don’t worry about that.
Step back, focus on the basics. Languages come and go, but the most successful developers are problem solvers. Build your programming on algorithmic thinking and everything else will fall into place.
These technologies are just tools and if you know what the problems are, you will know which tool to use to solve them.
5. Not Backing Up Code
Not building the right habits to protect your code is frustrating to new developers, and disastrous to experienced ones.
As a programmer, it is so important to save and backup your work constantly. It’s no different than working on an important document or spreadsheet, which is saved frequently.
Learn how to manage your files with Git . Any version control really, the software you use does not matter as much as knowing how to use it well. You don’t want to lose an important change if your computer crashes or a network fails.
6. Complicated Code
Coding is not an IQ test. It’s not a challenge to see who can use the most intricate functions or impressive looking files. The code should be written in the spirit of solving problems efficiently. Simple code is easier to write, easier to maintain, and easier to manage.
To be clear, simple code does not mean taking shortcuts. Simple code means getting down to the heart of the problem you want to solve, and solving it effectively. And pseudocode can help you with that. Here’s what pseudocode is and how it can make you a better coder .
7. Not Asking Questions
Programming is hard to do well, and getting better means learning new things constantly. The best thing you can do is read and study programming to get better, but when you need some additional guidance do not be afraid to ask questions.
Asking questions can be intimidating, but most veteran programmers are glad to share knowledge and ideas.
Just make sure you’ve done your research and have given it a real effort. Experienced developers are more likely to mentor you if they see you’re dedicated to learning. Maybe keep a programming journal to get better , by keeping track of the important questions and answers.
8. Not Planning in Advance
Writing effective software starts with good planning and design. If you wanted to build a house you would draw up a blueprint before building. Programming is no different.
Before you even write one line of code, identify what you actually want to accomplish. Know what the problem is, how you want to solve it. If you try and figure problems out while you’re writing code, you may find yourself missing the right solutions.
Separate the problem solving from the coding and life is good.
9. Not Taking Breaks
Take a break, really! Programming is mentally taxing, and going hours on end pushing your brain to the limits will eventually wear you down. Even worse than fatigue, you could suffer headaches or neck pains which are signs of computer eye strain .
When you hit the wall, it’s time to take a break. Get away from the screen for a little bit and do something you enjoy. Read a book, hit the outdoors, go hiking, go out for dinner, anything that gets you away.
You’ll be mentally refreshed, and when you return you might find a new perspective on your code.
10. Not Having Fun
Programming can be challenging, frustrating, and can sometimes be a downright grind. Make sure you enjoy the little things that you love about coding and don’t forget to have a little fun.
Whether you got into it to solve complex problems, build beautiful designs, or just to learn a new skill use what you love to keep you going. There’s a lot to love about coding so get inspired! Get excited to make something new, and see it through to the end.
Don’t Make These Programming Mistakes
It’s easy to get into a rut, either trying to get your head around something that should be simple, or trying to remember what some code does. Whatever the problem, avoid making all of these mistakes and you should find your code improving.
Still struggling? Don’f forget, there are plenty of hobbies for programmers that don’t involve code .