BT

How to Effectively Debug Software

| by Ben Linders Follow 29 Followers on Jun 09, 2016. Estimated reading time: 4 minutes |

Diomidis Spinellis, author of the books Code Reading and Code Quality, will speak about effectively debugging software and preventing errors at the GOTO Amsterdam 2016 conference.

InfoQ interviewed Spinellis about finding and fixing errors in software, principles for debugging software and how to improve the effectiveness of debugging, how to write code that requires less debugging, and what managers can do to support error prevention and handling.

InfoQ: What makes finding and fixing errors in software so difficult?

Diomidis Spinellis: If you think that writing code is hard, try debugging it. When you write a new function or method, you put together a few statements to form something that is only plausibly correct. When you debug a program, you take thousands or millions of code lines that are plausibly correct and try to find the error in them. This is bound to be much harder. Then you deal with tricky interactions between diverse systems and layers, CPU instructions that are executed at a rate of billions per second, bugs are difficult to reproduce, and stress from systems running in production.

Also, debugging is rarely taught in courses; hard-earned experience with all things that can go wrong is something that is difficult to condense in a lecture. In addition, because systems can fail in very different ways, you have to improvise and adjust your methods and tools as you go along. You may start with an observation, continue with data analytics, do a few experiments, and in the end deduce the bug’s cause. These are not typical beginner skills.

InfoQ: Are there any general principles for debugging software?

Spinellis: Sadly, due to the mind-boggling diversity of the things that can go wrong in software, I don’t think there are general principles one can follow to debug software. As a next best thing, I’ve identified three general types of approaches:

  • high-level strategies, such as drilling up from the symptom to the cause or confirming that some code satisfies its preconditions;
  • methods and practices, such as ensuring the efficient reproduction of a bug or increasing the prominence of a failure’s effects; and
  • general-purpose tools, such as those of the Unix command line, tracing (think of strace, dtrace, and systemtap), and the revision control system.

InfoQ: What are things that programmers can do to improve debugging effectiveness?

Spinellis: Start by setting yourself up for debugging success. Convince yourself that you will solve the problem, set aside ample time to debug it without distractions, persist, and, if needed, sleep over it. It’s important to continuously invest in your environment, tools, and knowledge. Acquire the software and hardware required to work effectively. For example, if your software generates huge debug log files, you should have the disk space, CPU capacity, and bandwidth required to process them efficiently. When debugging, you can easily suffer death from a thousand cuts, so spend some effort to organize and optimize your personal setup. This includes key bindings, aliases, helper scripts, shortcuts, and tool configurations; all these can significantly enhance your debugging productivity.

InfoQ: Are there techniques or methods to write code that will require less debugging?

Spinellis: Absolutely! Writing maintainable code — code that is readable, stable, and easy to analyse and change — also results in fewer bugs. Furthermore, approaches such as unit tests, code reviews, and the use of assertions all help minimize the errors that go into production code.

At design time, using high-level abstractions (for example, using a framework’s algorithm or container data structure instead of a hand-crafted alternative) reduces both coding and errors. It’s also important to make the program easy to debug. This includes providing facilities for detailed logging, reporting extensive context when internal errors occur, and sending details of problems and crashes to a central repository.

InfoQ: What can managers do to support error prevention and handling in their organization?

Spinellis: Putting in place the basic processes will help ensure software errors don’t get out of hand. Deploy and adopt an issue-tracking system and use it to triage and prioritize the issues you work on. Have software changes properly recorded in a well-maintained revision management system and link that with issue tracking; I’ve often fixed bugs simply by carefully studying a file’s history and changes. On the software construction front, promote the adoption of unit testing and include in the software’s build performance profiling, static analysis, and dynamic analysis, while maintaining a fast, lean, and mean build-and-test cycle. These will help your developers catch bugs early and fix them swiftly. Finally, on the operational side, deploy software in a gradual fashion, allowing the old version to be compared with the new one, strive for diversity in the tools you use and the environments you deploy on, and update tools and libraries in an organized way.

GOTO Amsterdam 2016 will be held June 14-15. It is a practitioner-driven enterprise-software-development conference designed for team leads, architects, and project management. InfoQ will cover the conference with Q&As, summaries, and articles.

Diomidis Spinellis is a professor at the Athens University of Economics and Business, editor in chief of IEEE Software, and author of the books Code Reading and Code Quality. Effective Debugging: 66 Specific Ways to Debug Software and Systems, his newest book, will be released on July 1, 2016.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Debugger is a very intriguing adventure! by Roberto Bera

I wrote a book of a debugger memory, but for now I've only the italian version.www.mondadoristore.it/I-piu-bei-bachi-software-...
The english version is under construction

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
BT