So today I worked on learning to debug my code in different methords. While I did not do a single final project today I learened about methords to debug such as working though the program line by like and marking variables. I also learnt how to use use the debugger in Pycharm with will be helpful for future usecases. And I also learnt the try...exept... functions in Python. I sloved some challenges online just so that I got a grip on getting to debug a variation of problems both syntax and logic.
On the whole these would be my 10 debugging tips:
Describe the problem
This one involves figuring out what exactly the problem is and what you want it to do. If you have a general idea of what the problem is then you can begin to try and solve it.Reproduce the bug
In some cases, the bug may not appear every single time the program runs. For these bugs it can be useful to try and catch them and reproduce them so that you get an error every single time the program runs rather than jusr randomly. This will help you understand where the program went wrong and what you can do to fix it.Play computer
This one is an important skill. You should be able to go though your program line-by-line and see the modifications as if you were the computer. You can also write the outputs and modifications down somewhere to help catch what might have gone wrong.Fix the errors
It is good to fix all the errors that are usually underlined red in some editors. The warnings (usually in yellow) are optional fixes if you know that somewhere down the line it all makes sence. This helps to get rid of syntaxs errors before you run the code that way you can focus on logic errors. You can also use the try...except block to catch any exceptions.Print is your friend
The great thing about print is that you can use it to see all the main changes and steps in your program. You can print out variables immediately after they have been modified and this can help you to catch if one of these outputs is wrong and you therefor need to do some changes to the way the variable is being modified.Use a debugger
This one seems pretty self-explanatory. It gives you a clear visual of what is going on at each step in your code so that you can catch at exactly which point the code went wrong. It also has freatures such as breakpoints, step over, step into, and step into my code.Take a break
This one is far more useful than most would think. Takihng a break allows your mind to reset so that when you come back you are not drained (or code-blind like I like to say) and can have a fresh persective and be able to generate new ideas to tackle the problem.Asking a friend
Sometimes a diffrent perspective or someone with a diffrent experience can help.Run often
Or any other physical activity. It helps to boost blood to the brain and clear your mood so that you are out of that sleepy, tired state and ready to start again.Asking StackOverflow
This is a useful one but before you ask any questions you should try to use other debgging methords and searching StackOverflow for questions that have already been asked.
There are many more debugging methords out there and most people tailor a few to suit them but these are the ones that I managed to get.
Top comments (0)