Channels ▼

Andrew Koenig

Dr. Dobb's Bloggers

Debugging: Art or Science?

November 29, 2012

More Insights

White Papers

More >>

Reports

More >>

Webcasts

More >>

Debugging is the hardest part of programming to describe systematically, because its very purpose is to deal with unsystematic behavior. A programmer plans for a program to behave in a particular way; debugging is what happens after the programmer discovers that the program is not behaving as planned. As a result, it is hard to write — or even think — about debugging in general. Every bug is different, so saying something that applies to the act of debugging requires finding something general to say about a bunch of unrelated specific cases that defy generalization by their very nature.

From this description, it is easy to see why debugging is like art. Art takes a part of our experience and distills it in a way that expresses the artist's personality. Different programmers will attack the same debugging problem differently, just as two different artists will portray the same scene differently. Moreover, although art encompasses many techniques that can be described in detail, written about, and taught, there is an inspirational core that is an essential part of each artist. Similarly, highly skilled debuggers often have difficulty describing how they came up with the idea that ultimately led them to the bug they were hunting.

Despite these similarities, I think that debugging is more science than art. To explain this viewpoint, I'd like to start with a particular view of what science is.

At its core, science is the process of modeling the physical world. Here, I am using model as a physicist or mathematician might: to describe an intellectual structure (such as a collection of equations) that behaves in ways that match some (but not all) of the properties of the physical world. There is much art in choosing such models in the first place, so it is fair to say that there is much art in science. However, where science differs from art is in how it deals with a model that does not match reality.

A work of art is always inaccurate; that's its point. If you set out to make a statue of an elephant, there's no art in simply using an elephant for the purpose. Yet nothing is as much like an elephant as an elephant is; which means that there will always be differences between any artistic representation of an elephant and an actual elephant. A model, however, is not an artistic representation. Although it is most useful if it is accurate, it does not attempt to be complete. Its purpose is only to explain — or predict — some aspects of the behavior of what is being modeled. So, for example, if someone can come up with a robot that behaves similarly to an elephant, but happens to be small enough to fit in the palm of one's hand, the size discrepancy is not relevant to the model's purpose. For the purpose of validating a model, it might not even be necessary to build a physical robot. The software itself might suffice.

In short, discrepancies between the world and its representation are a necessary part of art. In contrast, such discrepancies in scientific models are either irrelevant or something to be studied and reduced. This study and reduction is a fundamental difference between art and science.

A program is like a scientific model. We have an idea of what we would like that program to do; when we write a program, we want to make it behave as much as possible according to that idea. When our program does not behave that way (i.e., when we encounter a bug), we follow what is essentially a scientific process:

  • Is the difference between the model (i.e., the program) and reality (i.e., how we want the program to behave) what we think it is? For example, are we running the right program? Can we reproduce the misbehavior consistently?
  • Can we come up with a hypothesis that explains the difference between the model and reality? This step is probably the most creative part of debugging, just as it is the most creative part of science.
  • Once we have a hypothesis, how do we construct an experiment to test the hypothesis?

If our experiment shows that the hypothesis is correct, our debugging task is finished — at least for now. If not, the failed experiment may reveal how we were incorrect about the first step, namely finding the difference between the model and reality. After understanding how our hypothesis was incorrect, we can repeat the process with a new hypothesis.

There is no question that this analogy between debugging and scientific experimentation allows for much creativity, especially in the area of forming hypotheses. However, not all creativity is art, and there is more creativity in systematic experimentation than may appear at first glance. As a result, despite the creativity that so often goes into debugging, I think that debugging is more science than art.

Related Reading






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video