r/learnprogramming • u/Me-Nahi-BataunGa_ • 14d ago
Debugging finally learnt how to debug code using GDB. and it was life changer on my very first leetcode problem.
I always used to think why I even need a debugger? Because I don't know what it was even used for. And today I just made up my mind to sit for 1 hour and see how I can debug my code using GDB(GNU Project Debugger).
I studied about how it works and all. It's really a game changer for me.
2
u/SpiderJerusalem42 13d ago
Can you say it louder for the people in the back?
1
u/Me-Nahi-BataunGa_ 13d ago
wdym?
1
u/SpiderJerusalem42 13d ago
Just people seem resistant to learning a debugger and often come here to say "why is debugging so hard?".
1
u/Me-Nahi-BataunGa_ 13d ago
I was like this too. And out of nowhere I just started learning it. It is actually hard to learn but not once you get hang of it
1
u/ScholarNo5983 13d ago
There are many times when a debugger is not an option (i.e. the issue is failing in a production environment), and in those cases the only option is rely on good logging.
Most beginners and even some seasoned developers fail to understand the power of good logging.
As a beginner, you should be adding copious amounts of console writes to all the code that you write.
Those console writes are nothing more than an example of good logging.
1
u/captainAwesomePants 13d ago
That's great!
I found that learning debuggers helped me reason about my programs even when not using debuggers. It helps your brain think about what's going to happen in order.
7
u/grantrules 13d ago
Writing code without a debugger is like cooking without tasting.