There is a lot of uncertainty in the life of every developer. How will this section of code interact with that section? What if the network goes down? What if a gamma ray flips that bit? What's mom making for dinner? Does radon have a smell?


In fact, a large part of computer science is the study of how to eliminate uncertainty. At the top, there are formalisms like the pi-calculus and abstractions like CSP. Sometimes simple state diagrams can be a godsend. And even if you've never seen any of those, there is still room to do your part.


Noah sends in the following Javascript, which demonstrates how to eliminate uncertainty about program state inside conditional blocks.

function GetGridTable()
{
if (document.getElementById('" + gridPanelTable.ClientID + @"') != null)
    {
    return document.getElementById('" + gridPanelTable.ClientID + @"');
    }
else if (document.getElementById('" + gridPanelTable.ClientID + @"') != null)
   {
   return document.getElementById('" + gridPanelTable.ClientID + @"');
   }
   else
   {
return null;
    }
}

Beyond the simple "Are you sure?" above, Andy sends in a PHP example of how to be really certain that a file exists.


if(file_exists($fDir."announcement.jpg") and
file_exists($fDir."announcement.jpg")) {
$nImg = "announcement.jpg"; }

One of the problems with reasoning about both of those snippets is that the branches have differing side-effects. Programming conditionals where both branches produce the same data-flow can be tricky but --- as Ashton shows --- is not impossible, even in languages like C#.


if (BatchProcessor.ProcessBatch())
{

}
else
{

}

So, there: those three have been run into the ground. Just so you know, submitting something with the same title as a past story is a good way to convince me to not look at the submission. And for what it's worth, Noah sent his Javascript as an attachment, which Firefox was convinced I wanted to save or run, but not view. Please stop doing that too.