Debug Code by Writing Comments
/Here’s a programming tip for you. If you have a bug and you’re not sure why (or even where) it is occurring, spend some time writing comments in the code as you work through what it is supposed to do.
This is a great way to “explain to yourself” what the program does and it might even be useful information in the future. You never know. You can also spend some quality time refactoring the code so that variable and function names properly reflect what they are used for.
I like this approach because you then don’t look back on the time spent debugging as wasted. When you find the mistake that you made you can at least reflect that fixing it made the code better.