473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Comment Style

Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?

Cheers,
Nick

----
Mesham Parallel Programming Language
www.mesham.net
Sep 24 '08 #1
39 2829
polas said:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
/* ADVANTAGES */

* C89-conforming
* doesn't break when a line wraps (eg on code posted to Usenet!)
* robust against line-splicing

/* DISADVANTAGES */

* a little on the wordy side - you have to remember to close it
* doesn't nest

// ADVANTAGES

* nests // like // this
* terse

// DISADVANTAGES

* not C89-conforming
* breaks when a line wraps (eg on code posted to Usenet)
* fragile against accidental line-splicing:
foo(); // do the foo thing to c:\our_directory\
bar(); // now *why* isn't this function working?

As you can see, the advantages of one turn out to be the disadvantages of
the other.

For Usenet, /* */ is the clear winner, simply because of the line-break
issue: // with this kind of comment, when you post a very long comment
line as part of code that you present in a Usenet article, the code no
longer compiles.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 24 '08 #2
polas <ni**@helpforce.comwrites:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?

Cheers,
Nick

----
Mesham Parallel Programming Language
www.mesham.net
/* is much better for several reasons */

The most important one is that you can enclose multiple lines should
they break due to a different word wrap setting. Frankly I also think it
looks better :-)

/***************
* Comment block
* great eh
***************/
Sep 24 '08 #3
Richard Heathfield <rj*@see.sig.invalidwrites:
For Usenet, /* */ is the clear winner, simply because of the line-break
issue: // with this kind of comment, when you post a very long comment
line as part of code that you present in a Usenet article, the code no
longer compiles.
Or perhaps you should just refrain from word-wrapping code that
you post to Usenet.
--
"Am I missing something?"
--Dan Pop
Sep 24 '08 #4
On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
....
#endif

It's not just style - if your code doesn't use ANY other C99 feature
other than //, just replace them with /* */.

Lastly, it's possible to comment multiple lines with //

// comment\
Another comment
Sep 24 '08 #5
vi******@gmail.com writes:
On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
>Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?

// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif
It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
>
It's not just style - if your code doesn't use ANY other C99 feature
other than //, just replace them with /* */.

Lastly, it's possible to comment multiple lines with //
Huh? Could you explain that.
>
// comment\
Another comment
--
Sep 24 '08 #6

"Richard" <rg****@gmail.comwrote in message news:
vi******@gmail.com writes:
>It's also possible to comment out code with
#if 0
...
#endif

It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
The problem is that you might have comments in the code. Since comments
don't nest, the only option is the #if workaround.

Quite a few people don't put comments in function bodies for this reason.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Sep 24 '08 #7
Ben Pfaff <bl*@cs.stanford.eduwrites:
Richard Heathfield <rj*@see.sig.invalidwrites:
>For Usenet, /* */ is the clear winner, simply because of the line-break
issue: // with this kind of comment, when you post a very long comment
line as part of code that you present in a Usenet article, the code no
longer compiles.

Or perhaps you should just refrain from word-wrapping code that
you post to Usenet.
How?

Word-wrapping can occur at any of several stages between you writing
an article and somebody else reading it. You can usually avoid it by
keeping your lines sufficiently short, but that can breaks for quoted
text.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 24 '08 #8
vi******@gmail.com said:

<snip>
It's also possible to comment out code with
#if 0
...
#endif
Nit: #if is not a comment syntax. It's a conditional compilation
preprocessor directive. It is therefore ideal for temporarily disabling
blocks of code during development or debugging. The term "commenting out"
is a hangover from languages that don't have conditional compilation, thus
forcing their users to abuse the humble comment when disabling code.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 24 '08 #9
Richard<rg****@gmail.comwrites:
vi******@gmail.com writes:
[...]
>Lastly, it's possible to comment multiple lines with //

Huh? Could you explain that.
Read on.
>// comment\
Another comment
And there's the explanation.

Splicing of lines ending in \ occurs before comments are processed.
In translation phase 2, the two lines physical source lines quoted
above are spliced into a single logical source line:

// commentAnother comment

In translation phase 3, the comment is replaced by a single space
character.

*But* that's a truly horrible way to do a multi-line comment, and I
hope that vippstar was joking. The trailing backslash can easily be
missed. Furthermore, if the backslash is followed by a space
character, which is even easier to miss, the splicing is not done.
(IMHO this is a flaw in the language definition; a backslash followed
only by whitespace should be treated as a trailing backslash.)

Of course, it's trivially easy to comment out multiple lines using //:

// comment
// Another comment

and most text editors will let you replace the beginning of each of
a range of lines with "//", or delete "//" over a range of lines,
fairly easily.

It's often suggested that #if 0 ... #endif is a better way to
comment out large blocks of code. It's certainly better than
/* ... */, since that style of comment doesn't nest. But if the
block is very large, it can be hard to tell at a glance when you're
looking at the middle of the block that it's been commented out.
(Yes, some editors do color highlighting that can help with this,
but not all do -- and, personally, I don't really like color
highlighting.)

My suggestion: If you want to comment out a block of code, insert
"#if 0" at the start and "#endif" at the end *and* insert, say,
"*" at the beginning of each line.

Or you can use "//", but only if the code will never be used with
compilers that don't support "//" comments.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 24 '08 #10
polas wrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
/* */ works on both C89 compilers and C99 compilers
// works on C99 compilers, but it only works on some C89 compilers as
an extension. However, finding compilers which support that extension
is a lot easier than finding fully comforming implementations of C99.

"/*" makes everything that follows it a comment, up until the next */"
combination. This can be dangerous if you forget to type the
corresponding "*/", or mis-type it as "/*". The result is usually a
flood of error messages from the compiler; but the really dangerous
case is when the result produces no error messages; it just makes your
program malfunction.
"//" comments stop at the end of the line, which avoids that problem.

For the same reason, "//" has to be repeated on every comment line of
a comment, which means that it takes up more space. However, it's
generally a good idea to use some kind of formating to make multi-line
comments stand out:

/* This is a multi-line comment,
* this is the second line of the comment.
*/

If you're going to do that anyway, it doesn't make much difference
whether you type " *" or "//":

// This is the first comment line.
// This is the second comment line.

Personally, I find the second form easier to read and separate from
the actual code; Ben Pfaff apparently disagrees.

Many newsreaders can get confused by lines containing "//", and will
sometimes merge them with the following lines. This can make code
using "//" comments very hard to untangle.
Sep 24 '08 #11
On Sep 24, 11:32*am, Richard Heathfield <r...@see.sig.invalidwrote:
polas said:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* * */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?

/* ADVANTAGES */

* C89-conforming
* doesn't break when a line wraps (eg on code posted to Usenet!)
* robust against line-splicing

/* DISADVANTAGES */

* a little on the wordy side - you have to remember to close it
* doesn't nest

// ADVANTAGES

* nests // like // this
I wouldn't call that nesting, that's just including the comment start
sequence inside a comment, if it really nested then the comment would
continue to the next line in your example.

Note that you can do the same with with C-style comments:
/* this /* is /* legal */

so I don't see how the C++-style comments have an advantage here.

--
Robert Gamble
Sep 24 '08 #12
Richard wrote:
vi******@gmail.com writes:
>On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
>>Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif

It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.

--
Ian Collins.
Sep 24 '08 #13
Ian Collins wrote:
Richard wrote:
>vi******@gmail.com writes:
>>On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif
It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
When asking the author, he said it was because he might want to
use the pieces sometime.........
Yikes.
Sep 24 '08 #14
Sjouke Burry wrote:
Ian Collins wrote:
>Richard wrote:
>>vi******@gmail.com writes:

On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif
It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
When asking the author, he said it was because he might want to
use the pieces sometime.........
Yikes.
Someone should have mentioned source control to him.

--
Ian Collins.
Sep 24 '08 #15
Eric Sosman wrote, On 24/09/08 19:02:
Richard wrote:
>vi******@gmail.com writes:
>>On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif

It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.

Seems to me that if you're not able to read code without clashing
colors, funny fonts, and dancing dingbats, then you probably shouldn't
be writing it. #if 0 or #ifdef NOT_YET and the like are perfectly good
ways of suppressing blocks of code, with the advantage that they can do
so even if the suppressed blocks contain /* */ comments.
Also if the block is commented out with /* */ comments then you still
have exactly the same problem Richard was complaining about, i.e. you go
to the middle of a commented out block and your editor does not do
colour coding you might not notice it is commented out.

Note that the editor I choose to use will colour the code either way.

<snip>
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Sep 24 '08 #16
Ian Collins <ia******@hotmail.comwrites:
Richard wrote:
>vi******@gmail.com writes:
>>On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif

It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
But no one leaves "commented out" code in for long, do they? Code
will
You are speaking for yourself or everyone? Its hard to tell sometimes.
only be conditionally compiled out during testing and restored before
the code is committed.
Will it? Thanks for that. I mus have been mistaken all those times I
came across huge swarths of commented out code on my travels then.
>
So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code.
Why? Because a smart arse like you says so? You must be totally
omnipotent to know how everyone handles their old code.
If you have a short
term memory issue, that's a topic for another group.
I have no idea what you're talking about but I assume you're taking a
cheap shot.

Sep 24 '08 #17
Sjouke Burry wrote:
Ian Collins wrote:
>[...]
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
When asking the author, he said it was because he might want to
use the pieces sometime.........
"60-80 percent" seems pretty high, but disabling big blocks
and leaving them in the source file is defensible. I've often
seen it done with code that implemented a once-necessary work-
around or optimization that isn't needed any more but is kept
around just in case. After all, the fact that circumstances have
already changed once is no guarantee that change has ceased ...

The compiler isn't really a Software Engineering tool, but
we've all used it as such in small ways.

--
Er*********@sun.com
Sep 24 '08 #18
Sjouke Burry <bu*************@ppllaanneett.nnlllwrites:
Ian Collins wrote:
>Richard wrote:
>>vi******@gmail.com writes:

On Sep 24, 6:06 pm, polas <n...@helpforce.comwrote:
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) - does
one way have any advantages over the other, or is the style exactly
that, a question of style?
// was introduced in C99.
/* */ was since C89.
It's also possible to comment out code with
#if 0
...
#endif
It's also possible to crack an egg with a jack hammer. That way is truly
horrible. Primarily because if you scrolled to the middle of a huge
block in an editor which did not colour code commented out code using
your way then you would not/may not notice it was commented out.
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
Me too. Collins is being a smart arse again and speaking for the entire
world from his little corner of perfection.
When asking the author, he said it was because he might want to
use the pieces sometime.........
It happens all the time in many, many place. its amazing how many places
dont even use a basic RCS system as well.
Yikes.
Yikes indeed.
Sep 24 '08 #19
Richard wrote:
Ian Collins <ia******@hotmail.comwrites:
>But no one leaves "commented out" code in for long, do they? Code
will

You are speaking for yourself or everyone? Its hard to tell sometimes.
Any well organised team.
>only be conditionally compiled out during testing and restored before
the code is committed.

Will it? Thanks for that. I mus have been mistaken all those times I
came across huge swarths of commented out code on my travels then.
I assume you fixed them.
>So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code.

Why? Because a smart arse like you says so? You must be totally
omnipotent to know how everyone handles their old code.
No, because an autocratic manager like me tells them to.

--
Ian Collins.
Sep 24 '08 #20
Robert Gamble <rg*******@gmail.comwrites:
On Sep 24, 11:32*am, Richard Heathfield <r...@see.sig.invalidwrote:
[...]
>// ADVANTAGES

* nests // like // this

I wouldn't call that nesting, that's just including the comment start
sequence inside a comment, if it really nested then the comment would
continue to the next line in your example.

Note that you can do the same with with C-style comments:
/* this /* is /* legal */

so I don't see how the C++-style comments have an advantage here.
Consider commenting out a block of code (ignoring for the moment the
advice to use #if 0 instead).

void func(void)
{
do_this();

// Let's try something here...
do_something_dangerous(); // blah blah
do_something_even_more_dangerous();

do_something_else();
}

Now I want to comment out the two lines:

void func(void)
{
do_this();

// // Let's try something here...
// do_something_dangerous(); // blah blah
// do_something_even_more_dangerous();

do_something_else();
}

If you tried the equivalent with /* */ comments, it would be more
difficult to keep things straight -- and to restore the original code
when you later decide to uncomment it.

// comments don't *really* nest, but they do the next best thing: if
you loosely think of multiple // comments on consecutive lines as a
single comment, then there is a kind of nesting going on:

// Start of outer comment
// Second line of outer comment
//
// // First line of nested comment
// // Second line of nested comment
//
// End of outer comment

But remember the arguments *against* using // comments: lack of
support in C90 (most C90 compilers do support them as an extension,
but you have to enable *other* extensions to get them), and
line-wrapping on Usenet.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 24 '08 #21
Richard wrote:
[...]
I have no idea what you're talking about but I assume you're taking a
cheap shot.
In another message posted just one minute later he wrote:
[...]
Collins is being a smart arse again and speaking for the entire
world from his little corner of perfection.
I think that's about all of Richard _'s comment style I
care to see.

--
Er*********@sun.com
Sep 24 '08 #22
polas wrote:
>
Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) -
does one way have any advantages over the other, or is the style
exactly that, a question of style?
// comments are a syntax error in compilers to the C90 standard.
If the compiler has options to accept the // comment you can no
longer tell that your source is portable. Bad.

Also, // comments do not adapt cleanly to Usenet, where there are
limits on line length. After wrapping they are converted to syntax
errors, regardless of the use of a C99 compiler.

/* */ comments avoid all those problems.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 24 '08 #23
CBFalconer wrote:
polas wrote:
>Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) -
does one way have any advantages over the other, or is the style
exactly that, a question of style?

// comments are a syntax error in compilers to the C90 standard.
If the compiler has options to accept the // comment you can no
longer tell that your source is portable. Bad.

Also, // comments do not adapt cleanly to Usenet, where there are
limits on line length. After wrapping they are converted to syntax
errors, regardless of the use of a C99 compiler.

/* */ comments avoid all those problems.
Until you accidentally nest them.

--
Ian Collins.
Sep 24 '08 #24
Eric Sosman wrote:
Sjouke Burry wrote:
.... snip ...
>
>Ha! I have come across programs, where 60-80 percent was commented
out. When asking the author, he said it was because he might want
to use the pieces sometime.

"60-80 percent" seems pretty high, but disabling big blocks and
leaving them in the source file is defensible. I've often seen it
done with code that implemented a once-necessary work- around or
optimization that isn't needed any more but is kept around just in
case. After all, the fact that circumstances have already changed
once is no guarantee that change has ceased ...
I would recommend that any such be controlled by:

#define DO_ALLOWANCEFOR_EVILFEATURE 1
....
#if DO_ALLOWANCEFOR_EVILFEATURE
/* funny code */
#endif

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 24 '08 #25
Richard<rg****@gmail.comwrites:
Sjouke Burry <bu*************@ppllaanneett.nnlllwrites:
>Ian Collins wrote:
[...]
>>But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.

Me too. Collins is being a smart arse again and speaking for the entire
world from his little corner of perfection.
[...]

You know, Richard, if you could manage to comment on things like this
without sinking to personal insults, a lot of us might be more willing
to talk to you.

You can disagree without being disagreeable.

Or you can continue being a smart arse.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 24 '08 #26
On Thu, 25 Sep 2008 08:03:07 +1200, Ian Collins
<ia******@hotmail.comwrote:

>But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.
You are a very funny man.
Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
Sep 25 '08 #27
cr*@tiac.net (Richard Harter) writes:
On Thu, 25 Sep 2008 08:03:07 +1200, Ian Collins
<ia******@hotmail.comwrote:

>>But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

You are a very funny man.
I think he was being tongue in cheek - hence my smartarse comments :-;

But now I'm not so sure ....
>

Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
--
Sep 25 '08 #28
On Wed, 24 Sep 2008 16:39:21 -0400, Eric Sosman
<Er*********@sun.comwrote:
>Sjouke Burry wrote:
>Ian Collins wrote:
>>[...]
But no one leaves "commented out" code in for long, do they? Code will
only be conditionally compiled out during testing and restored before
the code is committed.

So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
When asking the author, he said it was because he might want to
use the pieces sometime.........

"60-80 percent" seems pretty high, but disabling big blocks
and leaving them in the source file is defensible. I've often
seen it done with code that implemented a once-necessary work-
around or optimization that isn't needed any more but is kept
around just in case. After all, the fact that circumstances have
already changed once is no guarantee that change has ceased ...

The compiler isn't really a Software Engineering tool, but
we've all used it as such in small ways.
And sometimes it is there just as documentation. E.g., the
original code is clear, clean, and slow. The replacement is
clever, incomprehensible, and fast as hell.
Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
Save the Earth now!!
It's the only planet with chocolate.
Sep 25 '08 #29
Eric Sosman wrote:
Richard wrote:
>[...]
I have no idea what you're talking about but I assume you're
taking a cheap shot.

In another message posted just one minute later he wrote:
>[...]
Collins is being a smart arse again and speaking for the
entire world from his little corner of perfection.

I think that's about all of Richard _'s comment style I
care to see.
I am amazed at the percentage of his acquaintances who are these
"smart arses". I have yet to see a valid definition of the breed.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 25 '08 #30
Ian Collins wrote:
CBFalconer wrote:
>polas wrote:
>>Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) -
does one way have any advantages over the other, or is the style
exactly that, a question of style?

// comments are a syntax error in compilers to the C90 standard.
If the compiler has options to accept the // comment you can no
longer tell that your source is portable. Bad.

Also, // comments do not adapt cleanly to Usenet, where there are
limits on line length. After wrapping they are converted to syntax
errors, regardless of the use of a C99 compiler.

/* */ comments avoid all those problems.

Until you accidentally nest them.
At which point the compilers I use emit a warning.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 25 '08 #31
CBFalconer wrote:
Ian Collins wrote:
>CBFalconer wrote:
>>polas wrote:

Afternoon all. I was just wondering about this point - I have
(generally) used // for commenting a single line in C, but from
looking at code other people have written it seems many use /* */
(which I only use if my comment will be over multiple lines) -
does one way have any advantages over the other, or is the style
exactly that, a question of style?
// comments are a syntax error in compilers to the C90 standard.
If the compiler has options to accept the // comment you can no
longer tell that your source is portable. Bad.

Also, // comments do not adapt cleanly to Usenet, where there are
limits on line length. After wrapping they are converted to syntax
errors, regardless of the use of a C99 compiler.

/* */ comments avoid all those problems.
Until you accidentally nest them.

At which point the compilers I use emit a warning.
At which point you have to go through and remove the nested comment, or
find anther way to remove the block.

--
Ian Collins.
Sep 25 '08 #32
On 24 Sep, 20:52, Robert Gamble <rgambl...@gmail.comwrote:
On Sep 24, 11:32 am, Richard Heathfield <r...@see.sig.invalidwrote:
polas said:
[ // comments nest] // like // this
I wouldn't call that nesting, that's just including the comment start
sequence inside a comment,
it's what I'd call nesting.

if it really nested then the comment would
continue to the next line in your example.

Note that you can do the same with with C-style comments:
/* this /* is /* legal */
in this quote typos are mine

ANSI X3.159-1989 para 3.1.9
"Except within a character constant, a string literal, or a comment,
the characters /* introduce a comment. The contents of a comment are
examined only to identify multibyte characters and to find the
characters
*/ that terminate it. [footnote]"

"[footnote] Thus, comments do not nest."
so I don't see how the C++-style comments have an advantage here.
--
Nick Keighley
Sep 25 '08 #33
On 25 Sep, 09:32, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 24 Sep, 20:52, Robert Gamble <rgambl...@gmail.comwrote:
On Sep 24, 11:32 am, Richard Heathfield <r...@see.sig.invalidwrote:
polas said:

[ // comments nest] // like // this
I wouldn't call that nesting, that's just including the comment start
sequence inside a comment,

it's what I'd call nesting.
if it really nested then the comment would
continue to the next line in your example.
Note that you can do the same with with C-style comments:
/* this /* is /* legal */

in this quote typos are mine

ANSI X3.159-1989 para 3.1.9
"Except within a character constant, a string literal, or a comment,
the characters /* introduce a comment. *The contents of a comment are
examined only to identify multibyte characters and to find the
characters
*/ that terminate it. [footnote]"

"[footnote] Thus, comments do not nest."
so I don't see how the C++-style comments have an advantage here.

oops on a re-read I agree with you. There can be multiple
starts nested inside a comment but the first end terminates it

/* /* valid */

/* /* not valid */ */

--
Nick Keighley

Sep 25 '08 #34
CBFalconer wrote:
Eric Sosman wrote:
>Richard wrote:
>>[...]
I have no idea what you're talking about but I assume you're
taking a cheap shot.
In another message posted just one minute later he wrote:
>>[...]
Collins is being a smart arse again and speaking for the
entire world from his little corner of perfection.
I think that's about all of Richard _'s comment style I
care to see.

I am amazed at the percentage of his acquaintances who are these
"smart arses". I have yet to see a valid definition of the breed.
I found only two comments from him about "smart arse". He uses "arse" a
lot, but he varies the adjective. It's one of those words that tends to
accurately describe the user more often than it fits the person it
nominally is referring to.
Sep 25 '08 #35
Ian Collins wrote:
CBFalconer wrote:
>Ian Collins wrote:
>>CBFalconer wrote:
.... snip ...
>>>
/* */ comments avoid all those problems.

Until you accidentally nest them.

At which point the compilers I use emit a warning.

At which point you have to go through and remove the nested
comment, or find anther way to remove the block.
Oh well. I will just put up with the extreme anguish.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Sep 25 '08 #36
Keith Thompson said:
Richard<rg****@gmail.comwrites:
<snip>
>>
Me too. Collins is being a smart arse again and speaking for the entire
world from his little corner of perfection.
[...]

You know, Richard, if you could manage to comment on things like this
without sinking to personal insults, a lot of us might be more willing
to talk to you.

You can disagree without being disagreeable.

Or you can continue being a smart arse.
If he were smart, I wouldn't have minded his being an arse.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 25 '08 #37
On Sep 24, 3:39*pm, Eric Sosman <Eric.Sos...@sun.comwrote:
Sjouke Burry wrote:
Ian Collins wrote:
[...]
But no one leaves "commented out" code in for long, do they? *Code will
only be conditionally compiled out during testing and restored before
the code is committed.
So the only person to scroll "to the middle of a huge block" will be the
person who conditionally compiled out the code. *If you have a short
term memory issue, that's a topic for another group.
Ha! I have come across programs, where 60-80 percent was commented
out.
When asking the author, he said it was because he might want to
use the pieces sometime.........

* * *"60-80 percent" seems pretty high, but disabling big blocks
and leaving them in the source file is defensible.
Not if you are going to try to call yourself a software engineer.
.... *I've often
seen it done with code that implemented a once-necessary work-
around or optimization that isn't needed any more but is kept
around just in case. *After all, the fact that circumstances have
already changed once is no guarantee that change has ceased ...
Then there is a design document filed under the production incident
describing the problem and the workaround. Leaving commented out code
in the current released version of source code is indefensible.
>
* * *The compiler isn't really a Software Engineering tool, but
we've all used it as such in small ways.

--
Eric.Sos...@sun.com
A compiler is one tool among many including source control, build
tools, design and requirement documentation, bug tracking systems and
others. These are all used by software engineers. A compiler is just a
hammer to brute coders. (and we all know where that leads.)

Ed.

Sep 25 '08 #38
On Wed, 24 Sep 2008 12:48:03 -0700 (PDT), ja*********@verizon.net
wrote:
<snip other points about /* */ versus // >
Many newsreaders can get confused by lines containing "//", and will
sometimes merge them with the following lines. This can make code
using "//" comments very hard to untangle.
I've not seen that one, but at least one version of Outhouse Depress I
used some years back thought //something_no_space should be a URL and
added an http: to it -- even when quoted in a followup IIRC.

Of course quite a lot of code isn't and won't be posted on news, and
so need not care about news restrictions/problems. And if it
unexpectedly is, restyling comments is not that big a deal.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Oct 6 '08 #39
On Mon, 06 Oct 2008 05:12:51 GMT, David Thompson wrote:
On Wed, 24 Sep 2008 12:48:03 -0700 (PDT), ja*********@verizon.net
wrote:
<snip other points about /* */ versus // >
>Many newsreaders can get confused by lines containing "//", and will
sometimes merge them with the following lines. This can make code
using "//" comments very hard to untangle.

I've not seen that one, but at least one version of Outhouse Depress I
used some years back thought //something_no_space should be a URL and
added an http: to it -- even when quoted in a followup IIRC.
I remember the bad old days of having to post with OE. Even with cutting
and pasting to make it a proper bottompost, there was every manner of
objectionable usenet style with it, and it was *such* a black box.

Dialog and Opera took the place of OE and IE, may they rest in bitbuckets.

>
Of course quite a lot of code isn't and won't be posted on news, and
so need not care about news restrictions/problems. And if it
unexpectedly is, restyling comments is not that big a deal.

I know that David has mastered many syntaxes and seems to know the IEEE
stuff that exists as a substrate for, for example, C, C++ and Fortran.

I find myself forgetting what the legal comments are in a syntax:

/* ... */ C90
# perl
! fortran 90
// C99
@ dos
c fortran 77
--
Richard Milhous Nixon

Why is it that we rejoice at a birth and grieve at a funeral? It is because
we are not the person involved.
~~ Mark Twain
Oct 6 '08 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alessandro Crugnola | last post by:
Hi all, i need to use a regular expression to match javadoc style comments in a file, something like /** * Constructs a new Call instance. * * @param object the object the Function shall be...
1
by: Chuck | last post by:
I am working with C# on Visual Studio 2003 SP1 on an XP professional SP2 system. All of the *.htm files generated by "Build Comment Web Pages" are flagged as restricted sites when I try to view...
18
by: pocmatos | last post by:
Hi all, While I was programming 5 minutes ago a recurring issue came up and this time I'd like to hear some opinions on style. Although they are usually personal I do think that in this case as...
6
by: Rene Pijlman | last post by:
The code below results in an exception (Python 2.4.2): HTMLParser.HTMLParseError: bad end tag: "</foo' + 'bar>", at line 4, column 6 Should it? The end tag it chokes on is in comment, isn't...
6
by: patrick j | last post by:
Hi I've been testing out the "Conditional Comment" for IE. This is because for my web-site I want to have two style sheets, one for IE 6 and one for other browsers. Thus I hope to have my...
3
by: Martin P. Hellwig | last post by:
Hi all, I've been toying with python for about two years now. Not every day, just when I encounter something in my job (sysadmin) repetitively dull. The amazing thing is that like any other...
29
by: dbhbarton | last post by:
Had a thought that's grown on me. No idea if it's original or not- too inexperienced in programming- but I guess there's no harm floating it out there. Python wins big on readability, and...
0
by: karen987 | last post by:
Could someone please tell me what code to add here? I have a weblog, with daily news which readers can add comments to, which are stored in a database. The form to add the comments is on an ASP page,...
14
by: Siv | last post by:
Hi, Just busily coding away and removed a procedure from my code and all of a sudden an error came up miles away from the location of the piece of code I removed and it relates to the XML...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.