I run my code after I write every single part. A part can be a single line, or maybe it's a few lines I copy in. The main goal is that if I do have a bug, I know for sure that it is in the last section of code that I wrote because I'd been "testing" as I went along. This way, I usually am only ever chasing down a single bug at a time.
When you begin coding at a higher level, there are more formal ways to test if your software works in robust and automated ways, but they're not relevant to you yet. Be aware that this exists.
The actual process of debugging is pretty simple. If your code throws an error, it will tell you what the error is and where in the code the error occurred.
Read the error
If you do not understand some of the words in the error, look them up
Read the part of your code that made the error and reflect on why that may be
Look around for typos and basic syntax errors just in case
Most novice programmers don't do all those steps. Do all those steps. The next step is knowing how to find answers when reading the errors wasn't enough.
If the error is from some specific function or class from an external library, look up that function or class in the library's official documentation.
If the error is some Python specific thing, look it up in the official Python documentation.
If you're still stuck, phone a friend or ask online.
2
u/[deleted] Mar 24 '21
I run my code after I write every single part. A part can be a single line, or maybe it's a few lines I copy in. The main goal is that if I do have a bug, I know for sure that it is in the last section of code that I wrote because I'd been "testing" as I went along. This way, I usually am only ever chasing down a single bug at a time.
When you begin coding at a higher level, there are more formal ways to test if your software works in robust and automated ways, but they're not relevant to you yet. Be aware that this exists.
The actual process of debugging is pretty simple. If your code throws an error, it will tell you what the error is and where in the code the error occurred.
Read the error
If you do not understand some of the words in the error, look them up
Read the part of your code that made the error and reflect on why that may be
Look around for typos and basic syntax errors just in case
Most novice programmers don't do all those steps. Do all those steps. The next step is knowing how to find answers when reading the errors wasn't enough.
If the error is from some specific function or class from an external library, look up that function or class in the library's official documentation.
If the error is some Python specific thing, look it up in the official Python documentation.
If you're still stuck, phone a friend or ask online.