Which comment type do you prefer?
Also, when do you add comments to your code (if you do)? Do you add them whilst you're coding or do you go back and add them afterwards?Code:// This type
OR
/* This type */
Printable View
Which comment type do you prefer?
Also, when do you add comments to your code (if you do)? Do you add them whilst you're coding or do you go back and add them afterwards?Code:// This type
OR
/* This type */
Depends - if I'm just making a program to test something, I don't comment. If I'm planing to give it out to someone, I will comment some parts. I like doing this:
Code:/****************************
Function name
Function description
****************************/
ret functionname() {}
I use /* */ for comments outside function bodies, usually stuff like:and // for comments inside functions.Code:/*
* class Foo
* explain what it does here
*/
I use them both, depending on what they do best:
Code:// Bla bla bla (only need one line)
- SirCrono6Code:/*bla
*bla bla
*bla bla
*bla (need several lines)
*/
it depends... look at this piece of code:I do the C-style comments (/**/) for header information and multi line things... and sometimes in classes to sepreate functions. I use C++ comments (//) for single line things... sometimes I use a mix (not really) like this:Code:... if(p2.hp>0) //if player two survives
turn=2; //time for player two to attack
else //if player two dies
turn=0; //no more attacking
}
if(turn==2) //player two's turn
{
atkdam=p2.atk*static_cast<double>((1+rand()%100)/100.0);
atkdam+=p2.spd*static_cast<double>((1+rand()%25)/100.0);
defdam=p1.def*static_cast<double>((1+rand()%75)/100.0);
defdam=p1.spd*static_cast<double>((1+rand()%25)/100.0);
/*
How things are watered down:
atk==100%
def==50%
spd==12%
*/
...
Code://*********************************************//
// Title Of Section //
//*********************************************//
I prefer // comments. I rarely use the C-style ones. As far as when I put them in, anything related to the implementation of a function, etc. I write at the same time I am writing the code. Other comments (header comments, function descriptions, etc.) I write later.
If I use C-style at all, I use it in the javadoc fashion, e.g.
Code:/** This function does nothing.
* @param x a useless parameter
* @return 5
*/
int donothing(int x) {
return 5;
}
I prefer frame-like comments for function headers n such. They are visible enough to easily find the functions when searching the file but still doesn't make it messy like * do (IMO). I believe this is LISP style.
For normal comments a simple // does the job.Code://+---------------------------
//| Yada yada
//+---------------------------
int f()
{
return 0;
}
Code:// Yada yada
int x = f();
I only use C-style comments when I'm debugging and I want to "comment-out" a chunk of code to narrow-down the problem.
also *sometimes* i use the c-style comments for documentation at the top of the program for my teacher (he's strict about having a plan :( )
I don't think it really matters, but remember that there are compilers out there that do not allow nested /* */ comments. If you run across this when you are porting an application to a new compiler you will have to use #if 0 to comment out chunks of code that have been commented with /* */ comments. You probably won't run across this unless you are compiling with a very specific compiler for an embedded target.