the-generalist.com

  • Increase font size
  • Default font size
  • Decrease font size
joomla templates, wordpress themes, drupal, datalife engine, graphics, seo,
Home

Programming Advice: Learn to Use Debugging

E-mail Print PDF

Many programmers, especially those who are new to programming, don't use debugging tools. These tools are a huge timesaver when trying to track down issues with code. Beginners will tend to add print statements on the values they think are problematic. While this is a good solution sometimes, even for advanced programmers, if this is your only means of debugging you aren't getting the most out of your tools. If you're wrong, you have to add more print statements and start over. Instead, add a breakpoint. When your code hits this breakpoint you can use the debug window to see the current values of your variables. You can then use hotkeys to step through your code one line at a time and see what is happening. You can also set a later breakpoint and tell the program to continue running until it hits that point. To really improve how fast you can solve issues with your code, you should practice with these tools.

If programming in Python I use Eclipse with PyDev. In C++ I use Visual Studio. Both of these offer a variety of debugging tools. I'll cover more advanced debugging in a future article, but for now, start with simple breakpoints and the autos (Visual Studio) or variables (Eclipse) window. Put a breakpoint where you want to start viewing your code and make sure your autos or variables window is open. When the code hits your breakpoint you'll be able to see the values of your local variables in these windows. Try playing with the step over and step into functions to get a feel for how to use the tools.

As I said I'll post about more advanced debugging features in a future article. I don't want to overwhelm anyone with too many options at once. As an exercise I would start trying the debugging method rather than the print method as much as possible. Try to get a feel for which method is more efficient for which type of problem. Come back later and I'll have more options for you that will really unlock the power of your debugger.

 

Add comment


Security code
Refresh

Main Menu