Re: Commenting the source code.
From: Eric Sosman (eric.sosman_at_sun.com)
Date: 10/25/04
- Next message: Flash Gordon: "Re: Array initalization doubt."
- Previous message: Dan Pop: "Re: Commenting the source code."
- In reply to: Joona I Palaste: "Re: Commenting the source code."
- Next in thread: Ben Pfaff: "Re: Commenting the source code."
- Reply: Ben Pfaff: "Re: Commenting the source code."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 25 Oct 2004 10:46:33 -0400
Joona I Palaste wrote:
> Malcolm <malcolm@55bank.freeserve.co.uk> scribbled the following:
>
>>"Profetas" <xuxu_18@yahoo.com> wrote
>>
>>>My theory is that commenting whilst you are coding,
>>>will break your concentration on what you were programming.
>>>
>>>If it is something complex.
>>>
>>>Does anybody agree?
>>>
>>
>>Yes. Comments are for people, including you after some time, who need to
>>look at the code after it is finished. If you put in comments during actual
>>writing you may need to take them out, you may find it hard to "comment out"
>>code, and, worst of all, you may invalidate a comment and forget to change
>>it, something no compiler can catch.
>
> One of our source files over at work is rife with comments about some
> obscure kludges that had to be inserted and need to be removed in the
> future. But over the course of the program's development, no one has
> bothered to find out what these kludges exactly are, which part of the
> code they affect, and how (or if) they can be removed. So the file still
> has comments about "This kludge should be removed by version n" when
> we're already in version n+2. Actually the whole file needs complete
> replacing but no one has got around to designing a replacement.
Having dealt with many such "permanent temporary
fixes," I found myself wishing for a way to make the
compiler complain -- not now, but at some future date,
so the hack would work for the moment but would draw
attention to itself later on. At first, I thought the
compiler ought to have a construct for such things, but
I eventually changed my mind: The compiler, in and of
itself, is not a complete software engineering tool and
should not be (ab)used as such.
Still, one can often take advantage of assorted
preprocessor symbols that medium-to-large projects often
define. E.g.,
/* This ugly hack works well enough to let the rest
* of the system be tested usefully, but should be
* fixed before we actually release the product.
*/
#ifdef RELEASE
#error "Please fix before shipping"
#else
/* ugly hack goes here */
#endif
Symbols that discriminate "release" from "test" versions
are often useful for this purpose; so, too, are symbols that
specify product versions (you'll ship the hack in version 2.0,
but want to remember to fix it for 2.1). NDEBUG is sometimes
used this way, but "overloading" its meaning is not wonderful.
The main idea is to look for a symbol that will change at some
relevant point in the future, ideally a symbol that is somehow
connected with the need for the hack, and then to plant a time
bomb with a BIG comment explaining what the hack was for and
how to tell whether it can be dispensed with.
-- Eric.Sosman@sun.com
- Next message: Flash Gordon: "Re: Array initalization doubt."
- Previous message: Dan Pop: "Re: Commenting the source code."
- In reply to: Joona I Palaste: "Re: Commenting the source code."
- Next in thread: Ben Pfaff: "Re: Commenting the source code."
- Reply: Ben Pfaff: "Re: Commenting the source code."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|