When I encounter bugs, I trace the code line-by-line to see if there was anything that did not go as expected.
If this is challenging, try using large sets of data as it will override your brain’s ability to naturally solve the problem just by looking at it. I have some sets with just one element, some with floats instead of just integers, some with multiple digits in an element, and some with negatives just to be safe.
Look for patterns and see if there’s anything you can generalize.
See if you can reduce any steps or if you are repeating any steps.
Even after you’ve worked out general steps, writing out pseudocode that you can translate into code will help with defining the structure of your code and make coding a lot easier. You can do this either on paper or as comments in your code editor.
It helps understand what a particular function is doing and why.
Through the use of clear variable names, function names, and comments, you (and others) should be able to understand: Get feedback from your teammates, professors, and other developers. See how others tackled the problem and learn from them.Refer back to the problem to make sure you are on track.When you have your pseudocode ready, translate each line into real code in the language you are working on. If you wrote it out on paper, type this up as comments in your code editor. Then I call the function and give it some sample sets of data we used earlier.Remember that syntax will come more naturally over time and there is no shame in referencing material for the correct syntax later on when coding. Debugging throughout will help you catch any syntax errors or gaps in logic sooner rather than later.Take advantage of your Integrated Development Environment (IDE) and debugger.You understand the problem, the logic, basics of the syntax, etc.If you see someone else’s code or have someone to guide you, you can follow along.Stay away from comments such as: I try to write brief, high-level comments that help me understand what’s going on if it is not obvious.This comes in handy when I am working on more complex problems.But maybe you feel uncertain about doing it yourself and have trouble turning your thoughts into code at first even though you understand the syntax or logic.Here’s my process and some tips to tackling a sample problem that hopefully some of you may find helpful in your journey. There is a difference between the problem and the problem you think you are solving.