5 Common Coding Mistakes and How to Fix Them

We’ve all been there. You hit compile, you run the program, and everything explodes like an action scene straight out of a cheesy Michael Bay movie. With error messages whizzing by left and right, you ask yourself: Why isn’t this working?

On a bad day, your code works and you don’t know why. On a good day, it works, and you still might not know why.

But no matter what day it is, this could all be avoided. How do you ask? That’s actually a really great question and one that we’re excited to help you answer. 

NEGLECTING TO USE A SOURCE CONTROL SYSTEM

A source control (or version control) system is a system used for the management of files, documents, source code of computer programs, or anything else related to a large collection of information. Whether you’re writing a simple application on your own or collaborating on a large software development project as part of a team, source control is a vital component of the overall development process. 

Source code management systems like Git allow you to track your code changes, view the complete revision history for your code, and go back to earlier versions of a project when needed. You can also easily collaborate on code with your team, isolate your work until it’s ready to go, and quickly troubleshoot issues by identifying who made the changes and what those were. Simply put, source control systems can help streamline the development process and save you from pulling out your hair after realizing you’ve made a huge mistake.  

NOT WRITING FOR THE “FUTURE YOU”

When programmers build software, they do so based on requirements that are likely to change in the future. Why do these requirements change? Well, the software moves, grooves, and interacts with the real world, which is very dynamic. When these requirements change, developers, who maybe didn’t write the OG version, must incorporate the new updates. In order to do that without the need for their secret stash of emotional support chocolate (anyone else turn to candy in times of stress?), code readability is key!

In order to develop readable source code, we should all ask ourselves: “If I re-read this piece of code in fifteen days or one year, will I be able to understand the abstraction I’ve created?” or even better, “If a programmer who just joined the development team reads my software, will they be able to understand what I’ve written?”

There are many tools and practices that increase the readability of a project, including:

  • Code review
  • Keeping the code concise
  • Meaningful variable and function names
  • Tests as documentation

Writing for the “future you” by using readable source code will save you valuable time, resources, and headaches all the while increasing productivity and collaboration. A win-win-win if you ask us.

REFUSING TO CHANGE BAD CODE

Every great programmer has written a lot of bad code. A lot. It’s par for the course and a completely normal part of the process. One of the most important things to remember when you’re coding is to be open to changing your code in order to get it to a better state. You do this by learning different and more effective ways to solve problems. 

When lifting weights in the gym, there is a certain correct “form” for each type of exercise. The better your form, the more effective the workout. Code is very similar to that. You should always audit your code and see if you could write it more clearly and effectively. 

It’s okay to make mistakes. Just know that you always want to be thinking about how you can improve your code. 

FORGETTING TO TEST (MANUAL AND AUTOMATED)

Speaking of refusing to change bad code, one easy way to identify that aforementioned bad code is to test, test, test! Sometimes we as developers miss the most obvious errors, or perhaps we know about them but tell ourselves that we’ll “come back to them later.” Every programmer has played this risky game before, but then it’s time to deploy the website or do a demo for a client. The programmer pulls up the brand new site for them only to be greeted by an aggressively bad and ugly-looking server error message. Not ideal. 

That’s where testing comes in. It’s like your BFF that keeps you from looking silly in front of the people who pay you. That said, testing, like your BFF, can be easy to take for granted because it’s always there. We’re here to remind you about the importance of testing and to appreciate the value it provides (oh, and to also tell your best friends thank you because they’re your best friends and they deserve it). 

 So what are the benefits of testing — both manually and automated — and what can it save you and your team? 

For starters, testing can save you hours and hours of debugging. When you have tests that your code needs to pass, you prevent bugs from creeping in. You’ll catch all of the little things like syntax errors and incorrect values that sometimes make it to the next phase of your pipeline. 

Testing also makes you think about your code before or as you write it. This can help you better identify which parameters you should expect, understand why you’re writing the code in a specific way, and learn how you think the user could break the code. By the time you finish a certain task, you’ll know everything about the nuts and bolts behind it. 

Regularly testing your code can also help you write efficient code the first time, give you documentation for the application and keep deployments smooth as a fresh new jar of Jif peanut butter. 

AN EXPECTATION THAT YOU WILL EVENTUALLY FULLY UNDERSTAND ALL ASPECTS OF PROGRAMMING

Joel Spolsky so perfectly coined the term “duct-tape programmer,” which does an amazing job of describing how software is actually built. 

Most people think software is built like a rocketship — expertly designed, crafted, manufactured, and launched without a hitch. It sounds great! In reality, however, building software is more like repairing a speeding go-kart as it races down a hill, using only duct tape and WD40.

It’s a process full of twists and turns, adjustments, and in-the-moment changes. Don’t let unreal expectations of how the world works cloud your judgment or fill your head with doubt. You might have absolutely no idea what you’re doing sometimes. And that’s okay. That just means you’re finding your way. 

CONCLUSION 

Everybody makes mistakes, and coders are no exception. When you’re writing code, paying attention to the small details can help dramatically. Employing smart strategies like using a source control system and writing for the “future you” with crystal-clear readability in mind will pay dividends. As will not being afraid to change bad code, regularly testing the heck out of it, and realizing that coding is an ever-evolving process. Practices like these will not only help to prevent you from making mistakes in the future but will also level up your programming skills. 

And that is what we like to call a blockbuster ending!

We believe anyone can learn how to code if they put in the time and effort. If you’re ready to take the leap, contact us today, and let’s chat about how you take part in Inventive’s Coding Bootcamp!