Re: trouble creating array of objects

From: Richard Heathfield (dontmail_at_address.co.uk.invalid)
Date: 12/09/03


Date: Tue, 9 Dec 2003 20:12:30 +0000 (UTC)

Martijn Lievaart wrote:

> On Tue, 09 Dec 2003 18:05:47 +0000, Gene Wirchenko wrote:
>
>>>When faced with this, I often decide to refactor. I already did before it
>>>became mainstream. I makes deciding easier, there is less risk involved.
>>>You can stop when sufficient bugs are squashed. You can regression test.
>>
>> I prefer to debug first. Get it right, then get it better. I
>> might try refactoring, but I would preserve the original in case I had
>> to fall back. The buggier the code, the less likely I am to refactor
>> first.
>
> Depends, but in general I don't agree. The buggier the code, the more
> difficult it is to get the bugs out. A little bit of refactoring can go a
> long end towards better code quality which makes debugging easier. (That
> is debugging as in getting the bugs out, not firing up the debugger).

Preliminary refactoring (the kind of tidying up of source that is common
here) can *eliminate* the need for debugging.

<saga>
In early 1990, I joined MumbleCo, a small insurance firm, and they taught me
a language called KMan, which was part of a wider expert system package
called Guru. They didn't hang about - I read the manual on Monday and got
to work on production code on Tuesday.

After I'd been there several months, I was asked to chase down a bug in an
Outstanding Losses report program (OSLOSS - nice name!). The program was
written in KMan, of course.

I read through the program, looking for obvious bugs. I couldn't see any,
but the code was a ***mess***. It was very, very, very badly written. In
fact, it was so badly written that it was effectively impossible to debug.
"Okay," I thought - "I'll just clean it up a little and then maybe I'll be
able to read it well enough to debug it. And *then* I'll track down the
original programmer and give him a good slapping."

So I backed up the source, and then went through the sort of review process
that those who use this newsgroup a lot will be familiar with - the moral
equivalent of gets() to fgets() and void main() to int main(). Once I'd
cleaned the code up, it looked a LOT better. Yes, I could debug this, I
think. So I plugged in the case data and stepped through the code. The bug
didn't appear. I ran it through the original code again. Yep, bug. New
code, no bug. Ha! So I was right in my hypothesis that my clean,
well-structured code was far superior, and far more robust, than the kind
of crap written by... whom?

I scrolled to the top of the source and read the intro block for the first
time, to read the programmer's name.

You're ahead of me, I know. Yes, it was me. My very first KMan production
program, written on that very first Tuesday.
</saga>

-- 
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton


Relevant Pages

  • Re: no debug info
    ... To ease debugging, the compiler does not optimize the code in a debug build. ... One is that your program has uncoverered a bug in the optimizer. ...
    (microsoft.public.vc.language)
  • Re: Cant create Device
    ... I thought I was fairly clear about why I can't use the debug ... I mean, I suppose for trying to resolve this particular bug, I could remove ... > it, turn the debug level up, enable unmanaged debugging, and examine the ... > the reason theirs works and yours doesnt is clearly a bug in your code. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: no debug info
    ... typically the release and debug builds are ... compiled against different runtime libraries. ... > build, er, um while debugging, and then switch to the release build ... > One is that your program has uncoverered a bug in the optimizer. ...
    (microsoft.public.vc.language)
  • Debug help please...
    ... I have just discovered a bug in my application. ... the debug version, so the release version is fine. ... The output window is pretty long, so I have included it at the end of this ... Binary was not built with debug information. ...
    (microsoft.public.vc.mfc)
  • Re: interpretive vs. compiled
    ... Hardly a reason to never do TDD, ... been written with that specific bug in mind). ... Sorry, this should not be a political forum, where people adjust their rhetoric based on which camp they suspect their adversary lives in. ... Some people use the word "refactoring" to mean they thumped on a design for a while, broke things, fixed them, and only then checked in. ...
    (comp.programming)