Re: Coding Standards
- From: Martin Gregorie <martin@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Aug 2007 17:57:09 +0100
Lew wrote:
Karl Uppiano wrote:I've been experimenting with writing class specifications as ASCII text files structured as:-- except for JavaDocs, which I write copiously. It gives me a nice place to describe the class, member variable, or method, with the input parameters, return values and exceptions thrown, in a way that is far more structured than you would get with ad-hoc comments.
Matthias Buelow wrote:Which are exactly the kind of useless comments that clatter source code.
I thought the code should be expressive enough without all that chatter?
Documenting trivial details is nonsense. You should explain the big
picture in comments and why you did some details the way you did them,
and not verbosely reformulate parts of the source code.
While I agree with Matthias's points about commenting the more obscure parts of one's code, I cannot believe that he seriously is against the use of Javadocs. Javadocs are critical in Java source. They serve double duty - not only do they help future users of a class to use it correctly, they cover most of the non-trivial comments one would make about a class or method (or other exposed member). It's hardly "chatter".
Introductory text describing the class and its intended purpose,
limitations, etc.
repeat for all constructors
Constructor description
constructor header
end-repeat
repeat for all public or protected methods
Method description
method header
end-repeat
so that, once I'm happy that the spec is complete, correct, spell-checked and readable it can be turned into self-documented compilable code by adding:
- the class header and block
- turning descriptions into Javadoc comments and inserting HTML
formatting tags etc
- adding minimal blocks behind the constructor and method headers.
Once this has been done its easy to add implementing code and private methods.
So far its worked out pretty well, resulting in Javadoc output that reads nicely and manages to avoid the creation of separate documentation that must be maintained (but never is).
I agree with Lew about commenting the code: if a method is just inline statements then the method description is all that's needed, but more complex code can benefit from having descriptive comments dropped into it. These are always indented to match the code and use /* ... */ delimiters (never /**) because I don't think that this type of comment has any place in the Javadoc method description.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
.
- Follow-Ups:
- Re: Coding Standards
- From: Ed Kirwan
- Re: Coding Standards
- References:
- Coding Standards
- From: davidsamith@xxxxxxxxx
- Re: Coding Standards
- From: Karl Uppiano
- Re: Coding Standards
- From: Matthias Buelow
- Re: Coding Standards
- From: Lew
- Coding Standards
- Prev by Date: Re: How do I put my application online?
- Next by Date: Re: Coding Standards
- Previous by thread: Re: Coding Standards
- Next by thread: Re: Coding Standards
- Index(es):
Relevant Pages
|