Re: place comments in C++ .h or .cc files?
From: James Dennett (jdennett_at_acm.org)
Date: 02/18/04
- Next message: jeffc: "Re: place comments in C++ .h or .cc files?"
- Previous message: Chris \( Val \): "Re: Some Advice. Joec and Chris"
- In reply to: Francis Glassborow: "Re: place comments in C++ .h or .cc files?"
- Next in thread: jeffc: "Re: place comments in C++ .h or .cc files?"
- Reply: jeffc: "Re: place comments in C++ .h or .cc files?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 18 Feb 2004 07:50:20 -0700
Francis Glassborow wrote:
> In message <c0unua$rl9@dispatch.concentric.net>, Gianni Mariani
> <gi2nospam@mariani.ws> writes
>
>> Digital Puer wrote:
>>
>>> jeffc wrote:
>>>
>>>> "Digital Puer" <digital_puer@hotjail.comet> wrote in message
>>>> news:c0u1vg$1ba$1@daisy.noc.ucla.edu...
>>>>
>>
>> ... snipola
>>
>>> Suppose I'm providing the implementation .cc files as well.
>>> Should I just cut-and-paste the same comments for each
>>> method API from the .h files (and have additional comments
>>> in the body of the methods)?
>>
>>
>> Only if you want a maintenance head-ache. At most if a method is
>> commented in the header you can put a reference saying - see the header.
>>
>> If you have a well documented header (preferably using doxygen), you
>> don't need to repeat them and it will be bad because when changes are
>> required you'll need to edit all instances of the comment which is
>> prone to error.
>>
>> Or is there a higher expectation?
>
>
> It isn't the purpose of comments to fully document code. Comments should
> highlight elements that cannot be correctly expressed in code. The
> problem with comments in headers is that every time you touch a header
> all translation units that include it have to be recompiled.
True with most simple build systems, but a more advanced
build system could avoid this -- it's not hard to tell when
the only change in a header is in comments.
> For student
> level programs that does not matter, for interpreted languages (such as
> Java) it is irrelevant but for fully compiled languages used for large
> projects (with perhaps more than 500,000 loc) recompilation can be a
> significant problem and there is a limit to how many coffee breaks you
> can take in a day.
But in real programming jobs there are almost always other
things you can be doing if compilation takes a few minutes:
coding time is but a small part of the job.
For hobby code, recompilation time is rarely a big problem
(although I do have to curb my urge to over-use templates
when prototyping code in C++, otherwise my build times do
quickly become long enough to reduce my productivity).
> Keep comments succinct and to the point, do not change them unless you
> are changing the header in some other way. Write proper documentation as
> something else.
I'd disagree with this. The comments are often the most
valuable part of the header file, and in most situations
it is folly not to maintain them for fear of triggering a
rebuild. This is true for most projects with which I've
worked, and they are generally in the 1 million line+
range -- only one project was such a pain to rebuild that
we had fear of touching header files, and that clearly
indicated a problem managing dependencies (which ironically
might have been lessened had the documentation in the
header files been better).
If I could be more idealistic, maybe I wouldn't advocate
using C or C++ headers as the best places to document interfaces.
In my experience of commercial software development, however,
putting the documentation right in the header, where the compiler
gets _its_ view of the interface, gives the only realistic
chance that developers will keep the documentation up to date.
-- James.
- Next message: jeffc: "Re: place comments in C++ .h or .cc files?"
- Previous message: Chris \( Val \): "Re: Some Advice. Joec and Chris"
- In reply to: Francis Glassborow: "Re: place comments in C++ .h or .cc files?"
- Next in thread: jeffc: "Re: place comments in C++ .h or .cc files?"
- Reply: jeffc: "Re: place comments in C++ .h or .cc files?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|