School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,314 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,060 people online right now. Registration is fast and FREE... Join Now!




How do programmers count lines of code

 

How do programmers count lines of code

paser

9 Jun, 2009 - 06:51 AM
Post #1

D.I.C Head
**

Joined: 30 May, 2009
Posts: 57



Thanked: 1 times
My Contributions
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.

User is offlineProfile CardPM
+Quote Post


Nykc

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 07:15 AM
Post #2

This script is cheap!
Group Icon

Joined: 14 Sep, 2007
Posts: 6,475



Thanked: 43 times
Dream Kudos: 325
My Contributions
My IDE/Text editor has line numbers built into it.
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 07:25 AM
Post #3

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,701



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Moved to Corner Cubical smile.gif
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 07:41 AM
Post #4

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
QUOTE(Nykc @ 9 Jun, 2009 - 07:15 AM) *

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.
User is offlineProfile CardPM
+Quote Post

AdaHacker

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 10:16 AM
Post #5

D.I.C Regular
***

Joined: 17 Jun, 2008
Posts: 377



Thanked: 83 times
My Contributions
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.
User is online!Profile CardPM
+Quote Post

BetaWar

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 10:22 AM
Post #6

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 4,729



Thanked: 269 times
Dream Kudos: 1400
My Contributions
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:
CODE
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.
User is offlineProfile CardPM
+Quote Post

SixOfEleven

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 10:42 AM
Post #7

Code Guru
Group Icon

Joined: 18 Oct, 2008
Posts: 2,905



Thanked: 165 times
Dream Kudos: 725
Expert In: C, C#, XNA, Game Programming, Programming Concepts

My Contributions
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.)
User is offlineProfile CardPM
+Quote Post

Raynes

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 11:44 AM
Post #8

Resident Witch. No, really.
Group Icon

Joined: 5 Jan, 2009
Posts: 887



Thanked: 11 times
Dream Kudos: 225
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

bflosabre91

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 11:53 AM
Post #9

go sabres
****

Joined: 22 Feb, 2008
Posts: 658



Thanked: 12 times
My Contributions
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 smile.gif but that still doesnt mean 10 lines of code cant be as tough to write as 1000

This post has been edited by bflosabre91: 9 Jun, 2009 - 11:53 AM
User is offlineProfile CardPM
+Quote Post

KYA

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 12:43 PM
Post #10

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,186



Thanked: 489 times
Dream Kudos: 2825
Expert In: C, C++, Java

My Contributions
For the record, # of lines is not a very good metric for much anything.
User is online!Profile CardPM
+Quote Post

Raynes

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 12:44 PM
Post #11

Resident Witch. No, really.
Group Icon

Joined: 5 Jan, 2009
Posts: 887



Thanked: 11 times
Dream Kudos: 225
My Contributions
QUOTE(KYA @ 9 Jun, 2009 - 12:43 PM) *

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


I agree.
User is offlineProfile CardPM
+Quote Post

dance_monkey()

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 01:42 PM
Post #12

New D.I.C Head
Group Icon

Joined: 2 Mar, 2006
Posts: 20


Dream Kudos: 150
My Contributions
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
User is offlineProfile CardPM
+Quote Post

Tom9729

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 02:07 PM
Post #13

Debian ninja
Group Icon

Joined: 30 Dec, 2007
Posts: 2,129



Thanked: 53 times
Dream Kudos: 425
My Contributions
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).
User is offlineProfile CardPM
+Quote Post

baavgai

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 03:28 PM
Post #14

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,260



Thanked: 389 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
KLOCs!?! Not even IBM does that anymore. The real question is why would you care? tongue.gif

In any case, the wiki page on this is reasonably informative: http://en.wikipedia.org/wiki/Source_lines_of_code




User is online!Profile CardPM
+Quote Post

Pwn

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 03:34 PM
Post #15

D.I.C Regular
***

Joined: 25 Nov, 2007
Posts: 360



Thanked: 13 times
My Contributions
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: 9 Jun, 2009 - 03:37 PM
User is offlineProfile CardPM
+Quote Post

Locke

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 04:34 PM
Post #16

Treasure Hunter
Group Icon

Joined: 20 Mar, 2008
Posts: 3,938



Thanked: 292 times
Dream Kudos: 325
Expert In: Java

My Contributions
QUOTE(PsychoCoder @ 9 Jun, 2009 - 09:25 AM) *

Moved to Corner Cubical smile.gif


AGH!!!!! crazy.gif wink2.gif

I only use line numbers as a reference point. I don't really shoot for a specific line count as a project limit/goal, because it simply works differently for everyone. Comments can take space, I write code spaced out nicely (for readability)...many many factors to tie in here. So I just finish the project, then I use the line count as a reference when I decide to increase performance or something, after I've added all of my comments and such.

This post has been edited by Locke: 9 Jun, 2009 - 04:35 PM
User is offlineProfile CardPM
+Quote Post

ShaneK

RE: How Do Programmers Count Lines Of Code

9 Jun, 2009 - 08:37 PM
Post #17

require_once("brain.php"); //Fatal error :/
Group Icon

Joined: 10 May, 2009
Posts: 699



Thanked: 47 times
Dream Kudos: 75
Expert In: PHP, MySQL

My Contributions
For me, in PHP, the only reason the line number matters is for debugging purpose (For example: Fatal error: function so_and_so() not defined in c:/this/is/my/path/file.php on line 2) it tells me exactly where to look to find my error, and PHP counts everything. Empty lines, coded lines, comment lines...(and jEdit counts those for me anime1.gif)

Yours,
Shane~
User is offlineProfile CardPM
+Quote Post

onesmartguy

RE: How Do Programmers Count Lines Of Code

10 Jul, 2009 - 12:30 PM
Post #18

New D.I.C Head
*

Joined: 10 Jul, 2009
Posts: 1

Counting code is not a good metric for grading. A good programmer refractors his code making it more usable through out the project. I other words you can have 300 lines of code that does the same thing that 10,000 of code and even performs better.

With that being said. If you not counting for grading or braggin purposes it is pretty crazy how much code one can push out.
User is offlineProfile CardPM
+Quote Post

paperclipmuffin

RE: How Do Programmers Count Lines Of Code

13 Jul, 2009 - 01:19 AM
Post #19

WinWinWinWindows?
Group Icon

Joined: 16 Apr, 2009
Posts: 881



Thanked: 9 times
Dream Kudos: 400
My Contributions
QUOTE(Nykc @ 9 Jun, 2009 - 07:15 AM) *

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


+1 icon_up.gif

User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: How Do Programmers Count Lines Of Code

13 Jul, 2009 - 05:36 AM
Post #20

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,292



Thanked: 79 times
Dream Kudos: 150
My Contributions
Who cares really?

Its quality not quantity biggrin.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 02:20PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month