Re: FACTORIAL PROGRAM
On Apr 16, 9:57 am, "per9000" <per9...@gmail.com> wrote:
On 14 Apr, 11:58, "James Kanze" <james.ka...@gmail.com> wrote:
<snip>
/* This is a block comment in C. It has to be */
/* long enough to span several lines, in order */
/* to show the effect. */
I rather like it; ...
<snip>
Since this thread is FUBAR I have to ask this - When commenting code:
what style is "the best" one?
The one that uses comments to add information not otherwise
available.
(Also: when commenting code: what style do you use?)
Since I actually like to understand the code by reading the comments
alone I tend to like to have neat comments that are understandable.
Which means that you read one thing, and the compiler reads
another. Two copies to keep in synch. Doesn't sound like a
good idea to me.
Comments are for things that cannot be expressed in code. For
example, given something like:
void f(int* p) ;
in a header, a comment like:
//! \param p
//! a pointer to an int.
is not very useful. Something like:
//! \pre
//! p != NULL
is essential.
Also I hate ugly code that does the magic in a one-liner if a two- or
three-liner is equally good but provides more readability.
/*
* A nice comment that is really readable,
* on a few lines.
*/
Like all writing, a comment should be as long as necessary, but
no longer.
The above example has a tendency of getting bad indentation - pretty
much like the next example. But still: the above example is how I
comment most C-code. I find it extremely readable.
/*
* An ugly comment that is really still readable,
* on a few lines.
* BEWARE: ugly/bad indentation
*/
I don't really see any difference. At any rate, I can configure
my editor to do it one way or the other. Of course, in C, I'd
do it something like.
/* A pretty readable comment, which for */
/* whatever reasons requires several lines. */
Depending on context, I might add a header or footer line to it,
to clearly mark it off from the code. (This is probably just an
old habit, though, from the days before syntax coloring.)
I've seen people doing this, but I am not sure I like it:
/*
** More stars - better indentation.
** More stars - less neatness.
**/
Personally I am disgusted by comments like these:
/* A horrible comment that perhaps might be readable,
one a few lines - but here you have to use the
force to see where it ends. */
One-liners are invisible to me - they just disappear
/* I am invisible - weeee! */
In C++ and C# I tend to add an extra line before and after so that the
comments show (for some reason I do not use the /* ... */ style in C++
or C#):
No one does, except maybe for special purposes.
And doesn't your editor show comments in a different color than
the code? All of the editors I know do.
//
// this loop does something to j
//
for (...)
--j;
In general, it's very, very rare to need a comment within a
function body.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34