By Wayne Parrott - Vice President Product Development 

"If debugging is the process of removing bugs, then programming must be the process of putting them in." - Edsger Dijkstra 

I can’t recall any team or dev processes I have worked with that provided direction and guidance for debugging practices and tools. This is such an oversight considering 50% of development time is spent debugging. Amazing, huh?

The following slide and talking points are from a talk I gave at PhoneGap Day 2014 on debugging and GapDebug. It outlines a simple debugging workflow and provides a set of guidelines for which every developer should be aware.

debugging rulesPrint this chart and post it in your work area. Review it when debugging to help guide your process.

Debugging Lifecycle

The 3 phases of debugging are presented at the top of the slide. Be explicit by asking yourself, "What phase am I in?" Most of the time it's kind of obvious but...

bug detection phase

 Detection - In this phase you identify that your system or code is not performing to expectation. Bugs pop up at all phases of development, e.g., design bugs, bugs missed in testing, missing tests or bugs in your test suite, documentation errors... The worst bugs are those that get shipped and are found by your customers.

bug isolation phase

 Isolation - Once you have identified a bug or fault in your system, the next step is to isolate it to its root cause. Is this a design problem? Is it an implementation issue? Some bugs are easy to isolate, others can drive you nuts. Typically you need to replicate the problem and observe it first hand in order to accurately isolate it. Problem replication alone can be troublesome, especially intermittent and concurrency issues.

bug resolution phase

Resolution & Recovery - This is the fix phase where you implement a solution that resolves the bug. It also includes verifying the fix. If a fix is not verified, then it's not fixed.


9 Rules of Debugging

The 9 rules of debugging are from Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems by David Agans. I’m not big on rules. So I think of them more as the 9 tips and guidelines for effective debugging. Of these guidelines #3, “Quit thinking and look,” implies fire up your debugger if you’ve got one. Dig into the system and see what’s goofed.

It’s 2015. Use a Debugger.

Today’s modern debuggers are awesome and practically indispensable for rapid development of quality code. Yet I frequently see developers, even experienced developers, neglecting the debugger that is only a click away in their dev environment. Instead they opt to fill up their code with print and alert statements to trace and dump execution state. What’s the deal? When I’ve seen this, words like novice, amateur, and hack come to mind. Expand your skills, learn your tools and get back to coding more quickly. And stop junking up your code with crappy personal debug info that so frequently is left in the codebase commented out!

Debugger Breakpoints Rock!

Start by learning to use your debugger’s breakpoint facility. A breakpoint is a marker you place in the code that instructs the program to suspend execution when encountered. You can then resume program execution from that point. While stopped at a breakpoint you can typically use the the debugger tools to inspect the program’s execution state, such as local and global variables, execution stack and console output.

debugging in the Java IDE debugger windowEclipse Java Debugger stopped at a breakpoint

Environments that support conditional breakpoints, and more recently breakpoint actions (see below), let you replace those code cluttering print statements with clean, conditional breakpoints. With a conditional breakpoint you provide a snippet of code that is evaluated each time the breakpoint is encountered. When the snippet evaluates to true, program execution is suspended at that point. This approach avoids jacking up your code with ad hoc print statements.

debugging with conditional breakpointsGapDebug iOS Breakpoint Actions

And if you’re a Java programmer using an IDE such as MyEclipse, you’re really in for a treat. While program execution is suspended at a breakpoint you can modify the code in the debugger, roll back to an earlier point in the program’s execution and resume. Repeat this as often as required. How cool is that? And you can export and share your breakpoints or reload them for future debugging.

Wrap Up

Improving your debugging and trouble-shooting skills helps reduce frustration and gets you back to the creative task of coding. To learn more about becoming a better debugger check out the following resources:

 

About the Author

Wayne Parrott is Vice President of Product Development and co-founder of Genuitec LLC. He brings more than 21 years of software development and application life-cycle management to overseeing development of Genuitec’s successful MyEclipse product family. His debugger work began with MyEclipse's first JSP debugger in 2003. His most recent work is with GapDebug, the first full featured cross-platform debugger for iOS and Android Cordova (PhoneGap) apps.

Related Posts

A Day with Dani: Angular Coding with Angular IDE +... Now that I’ve acquired a pretty good amount of knowledge with Python, I have decided to test the waters of Angular development. Already being familiar with CSS, HTML and JavaScript, I was advised to start looking into learning this language. I love working with web technologies, so I went ahead and took an Angular crash course to get me started. Af...
Deep Black Theme for Eclipse Just Got Better Our Darkest Dark theme was a total hit last year, yet some of you continued longing for a total eclipse of your IDE. We jumped at the task and created the Deep Black theme for Eclipse, going way beyond providing the possibility to go #000. Its newest release has also fixed inconsistencies for some plugins.Both Deep Black and Darkest Dark - as well ...
MyEclipse 2018 Updates Are Here – CI 2018.9.... Continuous hard work on bringing you the best of MyEclipse has come to fruition: MyEclipse updates are here, with our newest release, CI 2018.9.0. Now there is support for newer Wildfly servers, and both compatibility with third party tooling like PDT and some bugs across the IDE have been fixed.Wildfly 11, 12 and 13These servers with new server co...
React Image Upload – How It’s Done File upload is a very important feature of web applications: it helps facilitate actions like setting a user's profile picture, setting up dynamic galleries, remote file storage, and file sharing, among many other functionalities. In this article, we will be looking at file upload (more specifically, images), using React web framework, to a Node.js...

Posted on Mar 2nd 2015