Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By doubledee

Thread: Counting Lines of Code

  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Counting Lines of Code

    When the current version of my website is done, I want to count how much code I actually wrote.

    But what is the proper way to do this?

    If I want "Lines of Code"...

    - Does that mean I cannot count Comments?

    - Does it mean I am not allowed to count carriage returns/blank lines?

    - Must it only be actual lines of code?


    Originally I was just going to go into NetBeans, open up each script, and use the last Line Number as the "Lines of Code" per script, but maybe that would make things inflated?

    What is the "industry-standard" on this topic?

    Sincerely,


    Debbie

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I can tell you this ...

    I might write a script that has 200 lines of PHP scripting, with no comments.

    Fou-Lu could do the same script (to do the same thing) with 50 lines of code.

    His script would be better written, faster, etc.

    I would think experience, expertise, and knowledge would make a huge difference in the length of a script.

    So should I charge someone more because I coded more lines? No, because my script is poorly written.
    Last edited by mlseim; 06-12-2014 at 04:46 AM.

  • #3
    Regular Coder
    Join Date
    Nov 2012
    Posts
    115
    Thanks
    7
    Thanked 12 Times in 12 Posts
    The way I usually do it is via Linux bash, but that's depending on the system you run it on.

    If you're developing on a Linux PC or hosting the project on a Linux server, you can easily do a wc -l from all files in your project, that'll give you the number of lines in all files in your project. This is including blank lines, comments and the like. Personally I don't mind this, but if you need it for a specific purpose, you might need to find a different way of doing it.

  • #4
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    I can tell you this ...

    I might write a script that has 200 lines of PHP scripting, with no comments.

    Fou-Lu could do the same script (to do the same thing) with 50 lines of code.

    His script would be better written, faster, etc.

    I would think experience, expertise, and knowledge would make a huge difference in the length of a script.

    So should I charge someone more because I coded more lines? No, because my script is poorly written.
    Right, but that doesn't answer my OP...


    Debbie

  • #5
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Thyrosis View Post
    The way I usually do it is via Linux bash, but that's depending on the system you run it on.

    If you're developing on a Linux PC or hosting the project on a Linux server, you can easily do a wc -l from all files in your project, that'll give you the number of lines in all files in your project. This is including blank lines, comments and the like. Personally I don't mind this, but if you need it for a specific purpose, you might need to find a different way of doing it.
    Right, but that doesn't answer my OP...


    Debbie

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,224
    Thanks
    10
    Thanked 269 Times in 268 Posts
    Do the wc -l and round the result up or down to the nearest order of magnitude depending on your goals of publishing such a number. That's the nearest you're going to get to an industry standard for "lines of code". Yes, seriously.

  • #7
    Regular Coder
    Join Date
    Aug 2006
    Location
    Richmond, CA
    Posts
    179
    Thanks
    3
    Thanked 10 Times in 9 Posts
    Most places I've working have a tool that spits out the counts (total lines, comments, blank lines, etc). The current place I work has just one count, total lines (which I presume includes blank lines and comments, but it's a guess)

    The question is, what are you trying to quantify? Because line count isn't very meaningful, and becomes less meaningful the more people are on a project.

  • #8
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Daniel Israel View Post
    Most places I've working have a tool that spits out the counts (total lines, comments, blank lines, etc). The current place I work has just one count, total lines (which I presume includes blank lines and comments, but it's a guess)

    The question is, what are you trying to quantify? Because line count isn't very meaningful, and becomes less meaningful the more people are on a project.
    There is no "team". I am the team!

    I want to tally up all of my code to get some sense of the effort that I put into my site. But I also want to be fair in how I measure.

    The original plan was to go into each file, write down the last line number in each file, tally those up, and then say, "My website is 25,000 lines of code!"

    But then I go to thinking... Is it fair to say I wrote 25,000 lines of code if there are actually 14,000 lines of code, 5,000 blank lines between the code, and 6,000 lines of comments?!

    To me, a comment should count, because I had to take the time and energy to write a thoughtful comment.

    Blank lines in between lines of code, probably not.

    See where I am going?

    The question is NOT about "coding efficiency".

    I just think "Lines of Code" - however you come up with that # - is some kind of indication how complex my website is.

    When I tell people I built my own website, they think, "Yeah, so what?! My 8 year built his own 'website' (which consists of 5 hard-coded HTML pages)!"

    Well, to me, it means a lot more when your website is 25,000 lines of code!!

    Sincerely,


    Debbie

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Posts
    454
    Thanks
    0
    Thanked 20 Times in 20 Posts
    did you try:
    1. open file.
    2. save to vaiable.
    2. find all comments and blank lines using preg_match.
    3. remove all comments and blank line from variable string.
    4. split remaining data into an array using line returns.
    5 get the count of total array items.
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    In writing a hundred lines of finished code you might actually have written three or four hundred lines that you rewrote over until you got the code right. The number of lines of code in the final version is no indicator of how complex the code is.

    A better indication is the number of paths through the code.

    A static web page has exactly one path. Each decision statement (if/case) multiplies the number of paths by the number of alternatives in that statement for each time that statement can be run. Each loop that can run a variable number of times multiplies the number of paths by the expected average number of time the loop will run.

    So a page with ten lines of code consisting of an if statement and a loop might have 1000 different paths making it equivalent to 1000 static web pages.

    Once you get to a few pages with a few hundred lines of code each you might be into billions of different paths.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Right, but that doesn't answer my OP...
    How about this?
    http://www.sei.cmu.edu/reports/92tr020.pdf


    That's 242 pages of how to count lines of code.
    Don't fall asleep before getting to the last page.
    Last edited by mlseim; 06-14-2014 at 02:21 AM.

  • #12
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    In writing a hundred lines of finished code you might actually have written three or four hundred lines that you rewrote over until you got the code right. The number of lines of code in the final version is no indicator of how complex the code is.

    A better indication is the number of paths through the code.

    A static web page has exactly one path. Each decision statement (if/case) multiplies the number of paths by the number of alternatives in that statement for each time that statement can be run. Each loop that can run a variable number of times multiplies the number of paths by the expected average number of time the loop will run.

    So a page with ten lines of code consisting of an if statement and a loop might have 1000 different paths making it equivalent to 1000 static web pages.

    Once you get to a few pages with a few hundred lines of code each you might be into billions of different paths.
    I didn't think this was such a difficult question to get consensus on?!


    So what would you propose, Felgall?


    In my OP, I certainly wasn't trying to imply anything about complexity. (I've spent weeks on queries and PHP that were less than 20 lines of code!)

    But I figured Lines-of-Code certainly could give me an "Order of Magnitude" factor.

    So my best guess was...
    Code:
    Lines-of-Code = Actual Lines-of-Code + Comments
    Sincerely,


    Debbie

  • #13
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,057
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    How about this?
    http://www.sei.cmu.edu/reports/92tr020.pdf


    That's 242 pages of how to count lines of code.
    Don't fall asleep before getting to the last page.
    Nice! (Only at Carnegie Mellon could someone have come up with that!!)


    Debbie
    mlseim likes this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •