<?php include("course_info.php") ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
 <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
 <link rel="stylesheet" href="classweb.css" type="text/css" />
 <title><?=$course_number?> <?=$quarter?> <?=$year?>: Hypotheses in Debugging</title>
</head>

<body>

<h2><?=$course_number?>, <?=$quarter?> <?=$year?></h2>
<h1><?=$course_title?></h1>

<h2>Hypotheses in Debugging</h2>

<hr />

<p>
A debugging hypothesis isn't just a guess
about which part of the code has a defect,
and it doesn't address how a defect got there
or what code "should" be there instead.
A hypothesis is not concerned with possible changes
or what effects they might have.
A debugging hypothesis is, first and foremost, a <em>detailed explanation</em>
how the current code produces the behavior you've <em>already observed</em>.
</p>

<h3>A medical analogy</h3>

<p>
Just as a doctor needs a good diagnosis before prescribing a treatment,
a debugger needs a good hypothesis before attempting to fix a program.
Like a diagnosis, <em>a hypothesis does not tell you what to do</em>;
it helps you understand what may be happening
so you can try to predict the results of experiments.
</p>

<p>
Just as a medical diagnosis can be supported or invalidated
by the results of examinations or lab tests,
debugging hypothesis can be supported or invalidated by experimental results.
Failed attempts to invalidate a hypothesis
lend us more confidence it may be correct,
and non-invasive tests are usually the best way to gain confidence.
An attempt to treat an illness or fix a bug is an experiment too,
it can be harmful if the diagnosis is incorrect, or the hypothesis false,
so it's best to gather support for the hypothesis first.
</p>

<hr />

<p>
Here is a pretty <strong>good hypothesis</strong>:
</p>

<blockquote>
<p>
The code failed to compile because the variable <code>Foo</code> (capitalized)
was declared on line 4,
and later the variable <code>foo</code> (uncapitalized)
was used on lines 8 and 12.
Because Java variable names are case sensitive,
in effect <code>foo</code> had been used but not declared,
so the compiler failed to find the symbol
and printed an error message to that effect.
</p>
</blockquote>

<p>
Note this hypothesis includes concrete details
that account for the behavior already observed,
in this case a compile-time failure.
One can imagine various experiments based on this hypothesis.
One experiment would be to change capitalization
in the use of another variable
to verify the prediction that it will cause a similar failure.
Another experiment would be to change the capitalization
in the declaration of the variable on line 5,
or in the uses on lines 10 and 12,
but not both, of course!
</p>

<hr />

<p>
Now that we've seen an example of a good hypothesis
and some predictions and experiments that might be based on it,
let's take a look at some inadequate hypotheses
that exhibit some <strong>common mistakes</strong>:
</p>

<blockquote>
<p>
Our hypothesis was that the variable should not be capitalized.
</p>
</blockquote>

<p>
This might be called a "prescription," but not a hypothesis.
It doesn't explain how the current code produces the behavior already observed;
instead it jumps ahead to suggesting an experiment,
although without saying so.
</p>

<blockquote>
<p>
We hypothesized that changing the capitalization would make it work.
</p>
</blockquote>

<p>
This is not a hypothesis, but it is almost a prediction.
The biggest problem with this <em>as a prediction</em>
is that the phrase "would make it work" does not clearly indicate
what <em>specific results</em> are expected from the experiment.
</p>

<blockquote>
<p>
Hypothesis: If we look at the code, we'll find a defect.
</p>
</blockquote>

<p>
I might call this a "procedural forecast."
It's not even a prediction
in the sense of stating the expected results of an experiment;
instead it seems to express hope for finding a hypothesis.
</p>

<blockquote>
<p>
Hypothesis: The mistake is in the loop.
</p>
</blockquote>

<p>
This might be a good hunch,
but isn't specific enough to be a hypothesis.
The right thing to do is pursue this hunch
and look for a specific defect in the loop,
then make a hypothesis that explains
how the postulated defect produced the failure already observed.
</p>

<p>
It's useful to mention hunches in your report,
whether or not they turn out to be good hunches,
but don't make the mistake of calling a hunch a hypothesis!
</p>

<hr />

<p>
Now that we've seen some good and bad examples of hypotheses,
it may help clarify the concept
to consider this <strong>definition of "hypothesis"</strong>:
</p>

<ol>
 <li>A statement that suggests an explanation for an observation or an answer to a scientific problem and can be tested experimentally;</li>
 <li>a proposed explanation of a phenomenon.</li>
</ol>

<p>
This definition (from the <a href="http://doe.sd.gov/contentstandards/science/docs/2005/Overview/glossary.doc">South Dakota Science Standards Glossary</a>) captures quite well the way a hypothesis functions in scientific debugging. It's important that each hypothesis explains the phenomenon you've observed&mdash;a failure, usually&mdash;and allows you to make predictions about the results you expect to observe when you perform experiments.
</p>

<?php /*
<ul>
 <li>A provisional explanation for observations subject to continual testing and modification.</li>
 <li>A tentative proposal made to explain certain observations or facts that requires further investigation.</li>
 <li>A proposed concept that is not verified but that if true would explain certain facts or phenomena.</li>
 <li>(1) A statement that suggests an explanation for an observation or an answer to a scientific problem and can be tested experimentally;
     (2) a proposed explanation of a phenomenon.</li>
 <li>An explanation that accounts for a set of facts and that can be tested by further investigation.</li>
 <li>A scientific idea about how something works.</li>
 <li>A tentative explanation for a phenomenon used as a basis for further investigation.</li>
 <li>A tentative explanation of a given set of data that is expected to remain valid after future observation and experimentation.</li>
</ul>

<p style="font-size: small">
Note: These definitions have been culled from the Web;
I believe including them here may be fair use,
but if you hold a copyright on one of them
and object to my listing your definition here,
please contact me.
</p>

<p style="font-size: small">
Note: These definitions have been culled from the Web;
I believe including them here may be fair use,
but if you hold a copyright on one of them
and object to my listing your definition here,
please contact me.
</p>
*/ ?>

<hr />

<p>
 <a href="http://validator.w3.org/check?uri=referer"><img
    style="border:0;width:88px;height:31px"
    src="http://www.w3.org/Icons/valid-xhtml10"
    alt="Valid XHTML 1.0 Strict" height="31" width="88" />
 </a>
 <a href="http://jigsaw.w3.org/css-validator/check/referer">
  <img style="border:0;width:88px;height:31px"
       src="http://jigsaw.w3.org/css-validator/images/vcss" 
       alt="Valid CSS!" />
 </a>
</p>

</body>

</html>
