How do programmers count lines of code

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 5590 Views - Last Post: 08 November 2012 - 05:06 PM

#1 paser  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 135
  • Joined: 30-May 09

How do programmers count lines of code

Post icon  Posted 09 June 2009 - 07:51 AM

SO when a programmer says ive written 500 lines of code, is that including white space and so on? or like just lines with code on them.
Is This A Good Question/Topic? 0
  • +

Replies To: How do programmers count lines of code

#2 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 725
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 08:15 AM

My IDE/Text editor has line numbers built into it.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 08:25 AM

Moved to Corner Cubical :)
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1001
  • View blog
  • Posts: 3,555
  • Joined: 05-June 09

Re: How do programmers count lines of code

Posted 09 June 2009 - 08:41 AM

View PostNykc, on 9 Jun, 2009 - 07:15 AM, said:

My IDE/Text editor has line numbers built into it.

Yes exactly... I just take the last figure.

So I guess yes it includes whitespace and comments, but I'm fairly minimal when using them (for internal code) anyway.
Was This Post Helpful? 0
  • +
  • -

#5 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: How do programmers count lines of code

Posted 09 June 2009 - 11:16 AM

Really, it depends on who you ask. Some organizations just count the number of line breaks in the source. Others count comments, but not whitespace. Others count only lines with actual code. Some even count based on program statements rather than physical lines.

Obviously, the numbers can vary dramatically depending on what you want to count, which is why you have to be careful about how much importance you place on lines of code metrics.
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1104
  • View blog
  • Posts: 6,913
  • Joined: 07-September 06

Re: How do programmers count lines of code

Posted 09 June 2009 - 11:22 AM

Well, considering that I typically just do inline comments, if any at all (most of the time I believe my code is readable enough without the comments) which ends up looking like this:
 myVariablePtr->next->next = otherVariablePtr->prev; // comment here

I also don't worry about adding excessive line breaks between functions/ classes (like a single break with no blank lines).
So, I just go with the number of lines the IDE says I have.
Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 942
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: How do programmers count lines of code

Posted 09 June 2009 - 11:42 AM

When in university, a professor said this about line count:

Line count should exclude comments, curly braces and blank lines. Mostly you should count lines that have semicolons at the end and lines that end with right brackets.

(This was on an operating system design course using C.)
Was This Post Helpful? 0
  • +
  • -

#8 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: How do programmers count lines of code

Posted 09 June 2009 - 12:44 PM

I typically count the number of lines as the literal number of lines from the top to bottom of the file, as shown by my editor. That includes whitespace and comments. Unless I'm specifically asked the number of lines of actual code.
Was This Post Helpful? 0
  • +
  • -

#9 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: How do programmers count lines of code

Posted 09 June 2009 - 12:53 PM

visual studio tells the number of lines, but i think that includes all white space lines and such. but what do you really need an accurate line count for? it just use it as a basis to see how much/little work i did today :) but that still doesnt mean 10 lines of code cant be as tough to write as 1000

This post has been edited by bflosabre91: 09 June 2009 - 12:53 PM

Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 01:43 PM

For the record, # of lines is not a very good metric for much anything.
Was This Post Helpful? 2
  • +
  • -

#11 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 610
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: How do programmers count lines of code

Posted 09 June 2009 - 01:44 PM

View PostKYA, on 9 Jun, 2009 - 12:43 PM, said:

For the record, # of lines is not a very good metric for much anything.


I agree.
Was This Post Helpful? 0
  • +
  • -

#12 dance_monkey()  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 02-March 06

Re: How do programmers count lines of code

Posted 09 June 2009 - 02:42 PM

I wrote a little program to count my lines of code for me... It shows me lines of code not including whitespace or comments, as well as lines of comments, and comment-to-code ratio... yea, I was bored
Was This Post Helpful? 0
  • +
  • -

#13 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 03:07 PM

I wrote a little script to generate some LOC-related metrics from my projects. I count comments and whitespace. I don't count the fixed-length license header that I usually have at the beginning of each file.

I think LOC is generally a horrible metric but you can use it to infer some interesting things about a project (eg. number of bugs).
Was This Post Helpful? 0
  • +
  • -

#14 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5642
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 04:28 PM

KLOCs!?! Not even IBM does that anymore. The real question is why would you care? :P

In any case, the wiki page on this is reasonably informative: http://en.wikipedia....e_lines_of_code
Was This Post Helpful? 0
  • +
  • -

#15 Pwn  Icon User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 458
  • Joined: 25-November 07

Re: How do programmers count lines of code

Posted 09 June 2009 - 04:34 PM

This is an interesting topic, and one I've occasionally wondered about. I wrote a program that was @500 lines long and comments were usually one line at the beginning of blocks, with a one line separator and an additional line of comment where needed. I prefer my comments on separate lines; it lets me quickly see sections of code and I think improves my ability to troubleshoot. When I see green, I know this is the next logical section.

I guess my program was actually closer to 400 lines of actual code. I'd say a better measure of metrics would be how much your program actually does in those lines of code. If there's a lot of textual input and output, then that should be weighted less than actual functions and such. Maybe somebody could come up with a code analyser like Word has for documents which breaks down so many character, sentences, paragraphs, etc. Maybe it could tell you how many characters in comments, how many functions, how many inline functions, how many blocks, etc. It would be superfluous information, much like the word count in Word, especially when it comes to loops and such, because a 10 line block of loop code might run 50 times and how do you account for that?

This post has been edited by Pwn: 09 June 2009 - 04:37 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2