Code statistics

This is a discussion on Code statistics within the Tech Board forums, part of the Community Boards category; Hi, Do any of you know of a program that will create statistics on the code of a projet? I ...

  1. #1
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448

    Code statistics

    Hi,
    Do any of you know of a program that will create statistics on the code of a projet?
    I mean, like the number of lines in each file, the comment and actual code there is...
    I would need to run on GNU/Linux.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Not meaning to sound like a smartass or anything, but what about just writing your own utility to do this? You should already have wc to give you a line count, but it should not be overly difficult to write a modified version that parses out commented lines and the like.

    ~/

  3. #3
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    I have been thinking of writing my own tool, and might end up doing so anyway, but I though that any tool that is already written would have already gotten rid of a lot of bugs I'd introduce. I'll give it a try, but suggestions of already-written software are still wellcome.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    I guess you're only considering using // style comments? How would you count something like if(a) /* Is a true? */

    is that a comment line or a code line?
    If you understand what you're doing, you're not learning anything.

  5. #5
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    you would just say something like

    If the line starts with a / then dont count it

    befcause

    if(a) /*my coment blah blah*/

    is still one line of code, but

    // my comment
    if(a)

    it wont count the first and itll just be one line
    Hmm

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    22
    What about this?
    Code:
    int x = 0; /* a comment.. lalalala
    some more stuff...
    */ x = 5;
    There are lots of different things to consider.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    The field of dreams
    http://www.chris-lott.org/resources/cmetrics/
    If you write it, they will run it.

  8. #8
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Quote Originally Posted by Spitball
    What about this?
    Code:
    int x = 0; /* a comment.. lalalala
    some more stuff...
    */ x = 5;
    There are lots of different things to consider.
    That's precisely why I was searching for something that had already all of this sorted out. The first line could be counted as `composite' and added to the count of both. The second line would just be a comment line and the third would be composite again.
    Of course, now I have to sort out how I'm souposed to recognize that, but that's another story.
    The program I made last night can already count the total number of lines, but I'm fighting to get it to count the blank ones for some reason.
    EDIT:
    Tried c_count from the link salem posted. It's good, but I still see a line-counting bug I fixed in my app. The last line doesn't contain a \n character and so it doesn't count it.
    Last edited by -=SoKrA=-; 01-01-2005 at 03:43 AM.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  9. #9
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    well couldnt you search for a "//" or a "/*" and if you find a "/*" search until you find a "*/" and what ever is in between those you count (or dont count depending on what you want to do with it).
    Keyboard Not Found! Press any key to continue. . .

  10. #10
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Quote Originally Posted by DeepFyre
    well couldnt you search for a "//" or a "/*" and if you find a "/*" search until you find a "*/" and what ever is in between those you count (or dont count depending on what you want to do with it).
    The way I'm making it, there are different functions that control each count. A count for total lines is one function and updates one counter, a comment-counter updates another counter. None of these functions have any knowledge of what happens with the other counters.
    An exception may have to be the comment- and code-counter, since the code-counter needs to know what a comment is, so I may do it all in one function.
    Then comes the problem of wether to count blank lines inside comments as blank lines or not count them at all. Of course I could also count the lines of code and then take that number from the total lines.
    I'll try to tacke a few of these problems a bit later on. I'm trying to build PlaneShift (man, what a load of dependencies!) right now and need to eat a bit as well.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Lies, Damned Lies and Statistics!

    Sure you're measuring something - but what exactly?

    I mean, if you're doing this in a production environment, it won't take too long for all the engineers to figure out how to write their code to make the "statistics" look "good". But simple statistics like this tell you nothing about the quality of the code in the file.

  12. #12
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Quote Originally Posted by Salem
    Lies, Damned Lies and Statistics!

    Sure you're measuring something - but what exactly?

    I mean, if you're doing this in a production environment, it won't take too long for all the engineers to figure out how to write their code to make the "statistics" look "good". But simple statistics like this tell you nothing about the quality of the code in the file.
    I'm just curious about how much code I've written in a particular project. There's no production enviroment and I'm not going to argue that a project is better than anotehr just because there's more code.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Code:
    wc *.[ch]
    Once you've calibrated it to your style of writing (say 20% of your source lines are blank or comment lines), then it's simple and quick, and probably not too far off any other answer you can come up with.

  14. #14
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Yes, but it's still a chalenge to write a program to do this. wc still gives a useful result, since most of those lines do something useful (comments are also useful)
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  15. #15
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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