All too often I see new developer focusing on learning how to write code, but not spending as much time learning how to debug code. Knowing approaches to help you find why code is not working is just as important as knowing how to write the code in the first place.
There a too many questions posted online that look like this:
“I’ve written this code but it’s not working and I don’t know why”
My first question is always “have you stepped through the code to understand what the code is doing?”. Many of these types of question and issues can easily be resolved just by using a debugger, stepping through the code and validating that each step does what you expect. As you are learning development skills, a lot of issues in code are from assuming the code is doing one thing but the way you’ve implemented it you have a subtle difference somewhere where you didn’t initialize something, you referred to the wrong variable, or the logic in an if statement is incorrect. Stepping through the code will help you find the point where everything’s working up to the point where there’s an issue.
Spend time learning how to use your debugger in your IDE of choice. There are of course many other complementary techniques to debugging code, like logging and trace statement, unit testing etc, but don’t overlook the usefulness of your debugger.
[Top tip series: rather than spending time writing lengthy articles over several days I’m going to try and post shorter, hopefully useful tips more frequently]