AN APOCRYPHL TALE

I agree with Neven's style:

>  if something then begin
>    dostuff
>  end
>  else begin
>    dootherstuff
>  end;

This is a true story of a bug that was VERY expensive to repair, and had the
above style
been used would never have occurred:

Once apon a time, long ago in Turbo Pascal days, there was a block of code
that went like this:

ComplexStatement1;
ComplexStatement2;
ComplexStatement3;
ComplexStatement4;
ComplexStatement5;
IF NOT OnceInABlueMoon THEN
BEGIN
  DoTheUsualThing;
END;

Because the code needed tidying, ComplexStatements 1 .. 5 were shucked off
to
a subroutine called DoComplexStuff, and the programmer, being a dab hand
with
the editor, quickly deleted the now superfluous ComplexStatements did a
quick test
and was off to the pub in time for the rugby.

The code now looked like this

DoComplexStuff

BEGIN
  DoTheUsualThing;
END;

Note that

  if NOT OnceInABlueMoon THEN

was accidentally deleted, but because BEGIN/END simply mark blocks, it
compiled OK.

As it turned out, Murphy's Law was demonstrated perfectly and
OnceInABlueMoon was
a condition that occurred at midnight on New Year's Eve before a leap-year.
Some 2 or 3 years after this alteration (and many subsequent revisions of
the software) on
New Years Eve 1995 the lights went out in Lower Hutt, Queenstown and
Westport
(maybe other places too).

True, the programmer should have been more careful (but everyone who hasn't
made a
dopey mistake raise their hand!), or the testing could have been better, but
by far the
easiest would have been to LET THE COMPILER FIND THE ERROR.  If the original
code had been written ...

ComplexStatement1;
{ etc. }
ComplexStatement5;
if NOT OnceInABlueMoon THEN BEGIN
  DoTheUsualThing;
END;

..   after the hasty deletion it would have been ...

DoComplexStuff

  DoTheUsualThing;
END;  // Compiler error here

... and would never have compiled.

Here endeth the lesson.

In memory of Dave Bottle, a very clever programmer.


Bob Osborn

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to