Debugging - Survival Skill for Software Developers.
I would like to start writing this post by telling you a story:
When I started my corporate journey and soon after my first few months of joining a reputed firm, Like any other fresher I was filled with the attitude that I will release something big in first few days and make an impact quickly. I already know how to do programming and I can change the way system works.
Little I knew at that time, that reality was far beyond my imagination. When my first one-on-one happened with my manager, I still remember his words “I don’t see zeal in you to learn”. I was shattered because I was working really very hard, but the way I was working was horrible and I still thank my manger a trillion times for giving me that feedback.
Looking back, when I see what went wrong, I feel one of the biggest reasons I failed was my poor debugging skills. Whenever I encountered any issue, without understanding the issue, I used to try every option available on google and still it won't work. When my manager used to ask me, why you tried that option out, I would say because when I googled the error, I got this resolution in Stack Overflow(Now when I think of the situation, I feel so embarrassed) .
So today I want to share my learnings with you on how to do efficient debugging and coding:
- Write the code that is easier to debug. - Debuggable code isn’t necessarily clean, and code that’s littered with checks or error handling rarely makes for pleasant reading. “easy to debug” is “every single time there’s an error, the program reports to you exactly what happened in an easy to understand way”
- Error messages are better than silently failing: To get closer to the dream of “every single time there’s an error, the program reports to you exactly what happened in an easy to understand way” you also need to be disciplined about immediately returning an error message instead of silently writing incorrect data / passing a nonsense value to another function which will do WHO KNOWS WHAT with it and cause you a gigantic headache
- Failure: Print out a stack of errors, not just one error. This will help you to identify the root cause very easily.
- Understand what the error messages mean. Though underestimated, this is very important. Once you understand the error messages, you need not to google the error every time and you can start root-causing the issue within few moments of looking at the error message.
- Debugging Journey should look like this(This is not the template, but just a simple technique that works well for me) : you need to reproduce the problem, then make a more minimal reproduction, then start coming up with guesses and verifying them, and improve your mental model of the system, and then figure it out, then fix the problem and hopefully write a test to make it not come back
- When Debugging, your attitude matters : The Problem Attitude : This is too Hard for me to understand. Better Attitude : Let’s learn the basics and see if that helps. always dug deep down into the basic understanding of the issue. This might take time in the starting to debug the issue, but you will reach at the solution real quick and enjoy the process).
- Watching people who knows what they’re doing is inspiring : I personally feel this is most important for a software engineer. Surround yourself with the people who chooses the right way to debug and approach the problem, observe how they are thinking and eventually you will also develop the same mental model.
- Documentation that you can trust makes a big difference - When nothing helps, open the documentation and start to dig deeper into that. There is a technique to read documentation. You don't need to start from page 0 and go to page 100. First give a glance to the document and then dig deeper into the section that you think might help you.
P.S : This is what I have learnt from my experience and reading different articles. I wanted to share this because I feel sharing is caring. Different people might have different opinions on debugging, and that's where we learn more and grow.
Thanks for Reading !!
Thanx for sharing 🙂👍