Thread: comments

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    30

    Cool comments

    According to you, how do you indent your code and comments? how do you write comments?

    e.g

    /*Variable declaration*/
    int i;


    or


    int i; /*Variable declaration*/


    it's always useful to know the way other pple work. thx

  2. #2
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    another thread....

    it varies....

    cause sometimes you write it like this and sometimes the other way round...

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    30
    Why do u say : "another thread..."?

    i just wanted to know what u thought was better i'm still a beginner and i want to know from pros like u.

  4. #4
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    ...

    It depends. Here's an example
    Code:
    ...
    /* Attributes of Cats */
    char name[8]; /* Name of the Cat */
    int age; /* Age of cat*/
    int weight; /* Weight of Cat */
    ...
    [EDIT: I wrote the example too fast and forgot the semicolons]
    Last edited by kinghajj; 07-15-2003 at 12:42 PM.

  5. #5
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    What he meant by "another thread" was that this is another noobie thread. Don't feel to bad, though. I have a lot of them too.

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    The most important thing is to write decent comments.

    Things like "variable declaration" and "name of cat" are not the type of thing you want to be commenting. This is simply because anyone with half a clue about C will know that a char array called "name" is an array for holding a name!

    Document why your code does things, and if complexity requires it, document the how. Don't document the blindingly obvious.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    It's different, how to comment your code

    you have to find your own way.....

    comments are there, to make the code more readable.....

    and "another thread"....

    => another funny thread

    I don't laugh.... I find just the question funny....

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>It's different, how to comment your code
    you have to find your own way....<<
    Not when you're working in a team. A common understanding/style is a better approach, imo.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    My style also varies some, but in general:

    A block comment before a block of code explaining what's about to happen, probably multiline comment

    A post-line comment to explain what this line does or what the variable is for
    int tramp; /* counts the number of hobos to date */

    Post-line comments also at the end of if/for/while/switch structures
    Code:
            }  // end of if (a != 7)
        }      // end of for lp2
    }          // end of if !done
    I will also mix /* */ and // in a program -- I'm not that much of a purist

    oops, forgot the close code. at least I remembered the opening tag!
    Last edited by WaltP; 07-16-2003 at 12:51 PM.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #10
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    [QUOTE]
    Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
    [/QUOTE]

  11. #11
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Don't comment things that can be easily understood from the code. Remember, documentation has to be kept synchronized with the code itself. If code is clear, but the comments are out of date, then the programmer doing maintenance has to figure out if the comment is in fact out of date, or if the code is actually doing something more than meets the eye, and wastes time on that. Of course, if your code does do something more than meets the eye, it should be commented.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  12. #12
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    I indent my code like this

    Code:
    int main()
    {
         char a,b,c,d;
         return 0;
    }
    I think that most people find it a lot easier to read than those "other" ways.

    Comment as needed. When you're learning, you might want to comment stuff that you'd never consider commenting later. Just comment whatever you think might confuse you.
    Away.

  13. #13
    Registered User
    Join Date
    Jul 2003
    Posts
    30
    At uni, my lecturer makes us comment on every bit of code. i think he's doing this coz there's many students who've never done programming before. i just love programming!!! (though i get some probs with C)

  14. #14
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282
    I generally don't comment (for personal use) unless I feel that I might forget what the hell it is.

    I usually write all the comments needed at the beginning
    of a function so that it is more detailed and readable. However,
    I'll add some comments next to some lines if I feel it is imp.

    I also keep two versons (one without comments) so that the code is more readable You know, that actually helps sometimes.

  15. #15
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    I always use // instead of /* */ comments just because I find it looks better. Although it is a pain to have to take out twenty //'s when you would have just had to take out the /* */'s. :P
    To error is human, to really foul things up requires a computer

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. GCC not able to distinguish comments inside string
    By Yasir_Malik in forum C Programming
    Replies: 11
    Last Post: 06-23-2005, 12:11 PM
  4. The Art of Writing Comments :: Software Engineering
    By kuphryn in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2002, 05:18 PM
  5. comment on my comments
    By anthonye in forum C Programming
    Replies: 8
    Last Post: 02-01-2002, 11:31 AM