View Poll Results: Percentage of your program lines in comments?

Voters
24. You may not vote on this poll
  • 5%

    7 29.17%
  • 10%

    6 25.00%
  • 15%

    3 12.50%
  • 25%

    5 20.83%
  • What is a comment?

    1 4.17%
  • 1-1 (one comment per line of code)

    2 8.33%

Thread: Percent of comments in your code?

  1. #1
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429

    Percent of comments in your code?

    How much commenting do you do?

    For instance, I have a project I'm working on in VB right now that is about 4500 lines and when I look at the stats, it says 25% of that is commenting. Now granted, I don't comment too much inside my code, but I do like to throw in good explanations of what a function/procedure is for and what certain random numbers mean (other than constants).

    Another thing that bumps up this number is an addon in the VB IDE that throws in 6 (name of creator, time/date of creation, name of procedure, and description + 2 seperator lines) lines minimum of comment block for each procedure that I decide to do error trapping on (most of them).

    I guess I'm just wondering what kind of percentages you guys have.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    i probably put anywhere between 20-25% commenting in my code. I usually have a block comment at the top explaining the purpose of the file, version history and updates, and also contact info in case i release the code to anyone. I also usually put a block comment at the beginning of a function explaining the return types and correct example of using the function (if it's a complex one), but if it's a simple function, I don't tend to comment it that much.

    One thing I like to do once a certain block of code gets insanely complex is to space it out quite a bit so that each "thought" in the code has its own distinct area, allowing me to easily distinguish the code from one part to another.

    As for line to line commenting, the only time I'd ever do that is if I was writing the code for a beginner's tutorial or something, otherwise it's just overkill and starts making your code look messier and harder to read then before (unless you figure out a way to do it nicely, heh)

  3. #3
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    I don't do a lot of commenting, since most of the code i write is fairly simple and no one except me reads it

  4. #4
    Microsoft Lover afreedboy's Avatar
    Join Date
    Nov 2003
    Posts
    189
    Quote Originally Posted by viaxd
    I don't do a lot of commenting, since most of the code i write is fairly simple and no one except me reads it

    me too. I am a beginner to programming. I don't need to write a lot of comments as my program is very simple. I have only four or five functions in my program.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Quote Originally Posted by afreedboy
    me too. I am a beginner to programming. I don't need to write a lot of comments as my program is very simple. I have only four or five functions in my program.
    I was thinking the same but now when I am working on a big (at least to me) project I regret that I didnt comment my early programs and got used to it. Now I am sitting here with 10-20 uncommented files and I need to comment them sooner or later if I want to understand what is happening if I come back after a longer period of not coding or if I want to release the code (most likely this will be the reason why I will comment the code).
    Last edited by Shakti; 07-01-2004 at 11:11 AM.

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    I often start a project and then stop working on it. Then I go back and work on the project again.

    I have a horrible memory, and I'm too lazy to try and figure out what the code does, so I comment every line.

  7. #7
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    jverkoey, I put the 1-1 comment in there just for laughs... but I guess we do have those kinda people: *looks at gcn_zelda*

  8. #8
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    1-1 comments are absolutely necessary in Assembly code.
    My Website

    "Circular logic is good because it is."

  9. #9
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Quote Originally Posted by ober
    jverkoey, I put the 1-1 comment in there just for laughs... but I guess we do have those kinda people: *looks at gcn_zelda*
    *cowers*

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    1-1 comments are absolutely necessary in Assembly code.
    Um no. you don't need a comment on every ret or or movl $0, %eax. These are simple enough instructions that the stand out by themselves

  11. #11
    .
    Join Date
    Nov 2003
    Posts
    307
    Example:
    12 modules each ~4000 lines of C, 1 main module with11000 lines of C - total comments 122000.

    -- about two comments per line of code. Also, there is a complete change history at the top of every module, and I'm not counting in this exercise. These histories range from 300 to 2000 lines long. This is what you have to do in very large, very complex systems.

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I'd think it's useless to comment every line of assembly. It's clear enough what a single line does, but perhaps not what small blocks of code are there to do.

    About the two comments per line of code and change histories... That seems a bit extreme to me. CVS seems to be a much more friendly way of doing that.

  13. #13
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Program documentation requirement for my courses is a lot like variables library, program & function headers. So most comments are in classes and their functions, my main program is usually already self documenting so it's clean.
    That said, my comment to code ratio could be 60:40 (that's right, more comments than code)
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  14. #14
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I practically never comment. If I need to fix something I put a comment there, and I have a few lins of comment at the top to sort of "entitle" my code file, but when it's time to compile I remove all of this. I selected 5%.

  15. #15
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'm not a big commenter. I know I should comment a lot more then I do, I just don't. There is a point of too much commenting however. Comments should enchance and not obscure the code. When I do comment I prefer multiple lines at the beginning of a function or large block. Also I use variables that are fairly clear in their purposes ( except i but everyone knows i is used for interger counting )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  2. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  4. code and comments check
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 01-17-2002, 12:45 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM