DEV Community

Cover image for Tips to debug code
Muhammad Harith Zainudin
Muhammad Harith Zainudin

Posted on

Tips to debug code

Bugs are frustrating. It is terrible. But to debug it, it is an art that you need to master. You need to have a mindset to not falter.
So this is the tips that I can come out of to debug your code

  1. Reproduce the behaviour of the bugs
    Take the payload or anything that make the bug comes out. Reproduce it. Regenerate it. Whatever you can do. Simulate it back. This is the first things that you need to do, to see what is the problem

  2. Go back to where it last worked
    This is the most easiest way. Add the code little by little and see, which code segments that produce the bugs. It takes time, but hey, at least we have progress right?

  3. Make changes one by one. Little by littles
    Speed and efficiency are good for programmers, but when it comes to bug, we need to be delicate. It is frustrating, but still we need to go through it. Changing many things at a time won't help you to find the bug and fix it. Change something, rerun, and see the output. REPEAT.

  4. Get your colleagues to have fresh perspective
    Don't stuck yourself for hours or days to fix the same things. Ask your colleagues to see from a new perspective. Take some time off and get fresh eyes on the bug. Get a different point of view

  5. Be responsible of the code
    Firstly, don't ever blame the compiler. Blame yourself. Assume that the problems is ours and never expect the code to work for the first time so that you don't get your hope high. Of course this will comes from experience. Have a mindset to throw away the code/module if you have to fix it 5-6 times or more. Just start from scratch. Start new. Sometimes, that's the wisest things to do

  6. Learn from the bug
    This is self explanatory. Each of the bugs that we produce, learn from it. Try to not repeat it in other projects. Ask yourself, and reflect

    • "What can I learn from this?"
    • "What did I do?"
    • "How could I prevent this in the future?" "Is there any tools or things that I can do to improve my coding skills?" With this mindset, slowly but surely, you will become a good programmer.

I guess that's all for now. If you have any other tips, do share it in the comment section below!

Cover Photo by Chris Ried on Unsplash

Thank you for reading :D

Psstt pstt :p
Do consider to love this article ❤️ and follow me! Why not right? It's FREE~
I would really appreciate it 👨🏻‍💻
Will be posting more on things related to AWS, Javascript, Python, Serverless and more!

Top comments (2)

codenameone profile image
Shai Almog

These pretty much echo my tips as a Java developer. They are universal. Language/platform agnostic.

harithzainudin profile image
Muhammad Harith Zainudin

Indeed. Eventhough we use different language for programming, the tips that you provide also are valid for other programming language! Thank you for sharing @codenameone