Comments

This is a discussion on Comments within the C++ Programming forums, part of the General Programming Boards category; Which comment type do you prefer? Code: // This type OR /* This type */ Also, when do you add ...

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    Comments

    Which comment type do you prefer?

    Code:
     // This type
    
    OR
    
    /* This type */
    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?

  2. #2
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    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() {}
    Do not make direct eye contact with me.

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    I use /* */ for comments outside function bodies, usually stuff like:
    Code:
    /*
     * class Foo
     * explain what it does here
     */
    and // for comments inside functions.

  4. #4
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    I use them both, depending on what they do best:

    Code:
    // Bla bla bla (only need one line)
    Code:
    /*bla
     *bla bla
     *bla bla
     *bla (need several lines)
     */
    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it depends... look at this piece of code:
    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%
    			*/
    ...
    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:
    //*********************************************//
    //               Title Of Section              //
    //*********************************************//
    Last edited by major_small; 01-18-2004 at 07:36 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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;
    }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    Code:
    //+---------------------------
    //| Yada yada
    //+---------------------------
    int f()
    {
      return 0;
    }
    For normal comments a simple // does the job.
    Code:
    // Yada yada
    int x = f();
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    /* For debugging */

    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.

  10. #10
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    me too doug!

    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 )
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  11. #11
    Registered User
    Join Date
    Jan 2004
    Posts
    37
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. removing comments of type '//' and '/*'
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2007, 02:24 AM
  2. String parsing(parsing comments out of HTML file)
    By slcjoey in forum C# Programming
    Replies: 0
    Last Post: 07-29-2006, 08:28 PM
  3. comments
    By nightingale in forum C Programming
    Replies: 32
    Last Post: 07-18-2003, 03:49 AM
  4. The Art of Writing Comments :: Software Engineering
    By kuphryn in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2002, 04:18 PM
  5. comment on my comments
    By anthonye in forum C Programming
    Replies: 8
    Last Post: 02-01-2002, 10:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21