3.5 best practices on how to prevent debugging

3.5 best practices on how to prevent debugging 3.5 best practices on how to prevent debugging 3.5 best practices on how to prevent debugging 3.5 best practices on how to prevent debugging
We can't promise you a life without debugging, however, these best practices can help all developers spend more time on programming instead of solving bugs.

Every one of us wants to avoid bugs in the code, however, we are not always successful. Based on our experiences, we have prepared a list of helpful tips on how to prevent as many errors as possible.

Fast feedback loop is a mechanism that is used to validate and get feedback on the code as every time a new part of code is added it’s also run to confirm that it’s working as expected. The goal is to get both positive and negative feedback as fast as possible to immediately improve the current code. This method also prevents long debugging time as errors are instantly discovered. Thanks to this method, code can be passed for code review with confidence that everything works as it should.

This technique is stronger with the concept of print out more. If you are in doubt whether a few single lines of code are correct, you can print each variable out to the console and check the results.

If in doubt print more out:

DEBUG: Article tags: ['lifestyle', 'education', 'news']
INFO: User 326 updated article 2816.
DEBUG: Database transaction took 0.118s.

The second tip to prevent errors in production is to cover the negative scenarios as well as the positives ones. Imagine that your task is to create a simple sign up form where the user fills in a name, an email, a telephone number and needs to agree with the terms and conditions.

At the beginning of our developer journey, we would probably put 3 boxes under each other, have the checkbox there and finally a submit button. At this point we would start to celebrate and think about how amazing we are. It took us a little amount of time and the results are already here! Until someone comes and starts filling the form.

Users are sometimes unpredictable and most often they won’t act as we think like for example, not filling in the name, inserting invalid email addresses or not agreeing with the terms and conditions. All these examples mentioned are the negative scenarios that we haven’t taken into account at the beginning and can lead to the necessity of refactoring the majority of code which could end up by missing a deadline.

Therefore, it’s really important to try to cover as many scenarios of the user journey as possible. Not only will it help you prevent errors that may occur later in production but also provide a much better experience for your users straight from the beginning. Don’t worry about missing some edge cases, you will gain these with experience.

Finally, it is helpful to have a readable and maintainable code base to prevent future debugging. Thanks to these two basic principles you are able to change anything in your code quickly and with minimal hassle. It also allows you and your team to quickly onboard new members because they are able to orient themselves in the code.

Sometimes it could be difficult to take care of these principles, especially with a larger codebase, however, there are great tools on the market that can help with that. Linters are definitely one of them as they allow you to check the code quality and readability locally as well as in the CI/CD pipeline. The cons for linters are that the output from every linter is different and therefore it’s not easy to consume the results from the console and also, it could start to be overwhelming once you need to keep more linters up to date on your machine.

The next step could be using automated tools like Codeac.io, one of the leading code review tools in the market. Codeac.io allows you to keep track of the configuration of analyzers as part of the repository so all of the team members are following the same rules. It also pinpoints the most crucial problems so you can prioritise fixing them. This should give you more confidence before sending your work for code review or to production.

SQL Injection exploitation can lead to reading or modifying sensitive data from the database.
SQL Injection exploitation can lead to reading or modifying sensitive data from the database.

Fast feedback loop is great for going step by step and making sure that the code works correctly. Together with thinking of both negative and positive scenarios, and having a readable codebase leads to reduction of errors in the future as well as speeds up the whole development process because in addition to preventing the bugs, resolving them is faster and done with greater confidence. To fully understand these concepts it’s necessary to experience as many different scenarios and apply them to see how powerful they are. By practicing you will make many mistakes, and that’s completely fine, take it as an opportunity to become a better developer. Not only will you learn exactly how to fix bugs in the code but better yet, how to prevent them altogether.


This brings us to the conclusion of our small series for junior developers focused on debugging. The first article was focused on how to come up with a debugging system, the second one on how to save time while debugging and here we focus on tips on how to prevent debugging. We hope that you found these tips useful and that this series helped to improve your debugging skills. Let us know if you have any other tips!

Ready to get started?

Use your favorite version control system to sign-up.

Sign up for free