How to debug? (Tips for newbies)
By: Calvin Cheng
Tags: Coding, Software Development, Debugging, Technology, Programming

I studied business in university and had little experience in software development. Debugging has been my greatest obstacle to become a software engineer. It is very confusing to find out my program doesn’t work as expected. I used to be a technology consultant. Creating a proposal in powerpoint never gave me the same level of confusion as programming did. If I had not found a systematic way to debug efficiently, I would have ended my career in software engineering. Therefore, I want to summarize some general debugging skills for newbies. Hope you can have a smoother path in pursuit of being a software engineer.

Firstly, locate the error messages in all the right places. When a program encounters into problems, it usually throws errors in different places. It can be misleading and confusing to read error messages in just one place. Try to go through all errors to have a comprehensive picture. For example, when your website doesn’t work, you can check the error in the browser as well as in the backend server.

Secondly, read the error message carefully. I used to find the error message, googled it and clicked the first Stack Overflow link immediately without even reading the error message. Sometimes the error can be as simple as missing a bracket. That can save your google time if you read the message first.

Thirdly, just google it. I think I don’t need to elaborate further for this part which is an inborn skill for all digital citizens.

Fourthly, read the official documentation. Most beginners get stuck after they google the error message as they either can’t understand it or those google results don’t accurately describe the error they are facing. You should then find out which lines of code cause the error and what functions, modules, libraries, SDK and/or API calls are involved. Search the official documentation related to that component and read the definition carefully. Usually, the documentation defines how your component should be written and what data type of variable should be put in. Cross-check with your code to see if there is anything wrong.

Fifthly, find tutorials on how to use that component. Rookie developers may just get confused after digging into the jargon-filled official documentation. You can try to google something like “How to use (component name) of (module, library, SDK or API name)” Some generous software engineer (like me 😊) may try to contribute back to the community by explaining how to use some complicated components.

Sixthly, brute force it! Sometimes you may not find any answer from the documentation and google. You may need to go through the process of trial and error, such as changing the data type of the variable, moving the component to different lines of the code and removing the entire component. Don’t forget to put a function to print out the result of your trial and error process.

Seventhly, the error can be related to the environment. I got very lost when I first heard the term environment in the software development. It is nothing scary but just some other programs surrounding your little program. Think of it like your bedroom. If your lightbulb is not working, you firstly try to see if there is any problem for the switch in the bedroom. Then, you may install a new lightbulb to see if it works again. Then, you may go to the living room to investigate whether the circuit breaker is triggered. Lastly, you seek help from an electrician. For your program, the error can be caused by the runtime version. Runtime refers to a piece of software where your program is executed, such as Java, Node.js and Python. Perhaps your component only supports a particular version. On top of that, your runtime maybe wrapped in a container environment. Container OS or the container itself can cause the error. In addition, other programs running in the host OS or the host OS itself may also cause the error.

Lastly, restart the computer but don’t do it in the production environment (SERIOUSLY!!!). Allegedly, it solves 80% of the computer problems but you may face the same error someday.

I hope you can really take away something from here and solve next bug with a little bit more confidence! Happy debugging😊