School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,149 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,862 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

#1 paser  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 66
  • Joined: 30-May 09


Dream Kudos: 0

Post icon  Posted 09 June 2009 - 06: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.
Was This Post Helpful? 0
  • +
  • -


#2 Nykc  Icon User is offline

  • Gentleman of Leisure
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 6,979
  • Joined: 14-September 07


Dream Kudos: 375

Posted 09 June 2009 - 07:15 AM

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

#3 PsychoCoder  Icon User is offline

  • apt-get install DIC.bin
  • Icon
  • View blog
  • Group: Admins
  • Posts: 16,214
  • Joined: 26-July 07


Dream Kudos: 12400

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Posted 09 June 2009 - 07:25 AM

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

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • Icon
  • Group: Members w/DIC++
  • Posts: 1,931
  • Joined: 05-June 09


Dream Kudos: 150

Expert In: PHP, MySQL, HTML, CSS, C#

Posted 09 June 2009 - 07: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

  • D.I.C Regular
  • PipPipPip
  • Group: Members
  • Posts: 466
  • Joined: 17-June 08


Dream Kudos: 0

Posted 09 June 2009 - 10: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>
  • Icon
  • Group: Moderators
  • Posts: 4,945
  • Joined: 07-September 06


Dream Kudos: 1500

Posted 09 June 2009 - 10: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 online

  • XNA Developer
  • Icon
  • View blog
  • Group: Moderators
  • Posts: 4,013
  • Joined: 18-October 08


Dream Kudos: 1100

Expert In: C, C#, XNA, Game Programming, Programming Concepts

Posted 09 June 2009 - 10: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

  • All your lambda are belong to us.
  • Icon
  • Group: Contributor w/DIC++
  • Posts: 1,375
  • Joined: 05-January 09


Dream Kudos: 300

Posted 09 June 2009 - 11:44 AM

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
  • PipPipPipPip
  • Group: Members
  • Posts: 822
  • Joined: 22-February 08


Dream Kudos: 0

Posted 09 June 2009 - 11:53 AM

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 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is offline

  • while(sad){!sad; awesome();}
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 13,183
  • Joined: 14-September 07


Dream Kudos: 3000

Expert In: C, C++, Java

Posted 09 June 2009 - 12:43 PM

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

#11 Raynes  Icon User is offline

  • All your lambda are belong to us.
  • Icon
  • Group: Contributor w/DIC++
  • Posts: 1,375
  • Joined: 05-January 09


Dream Kudos: 300

Posted 09 June 2009 - 12: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
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 20
  • Joined: 02-March 06


Dream Kudos: 150

Posted 09 June 2009 - 01: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
  • Icon
  • View blog
  • Group: Author w/DIC++
  • Posts: 2,279
  • Joined: 30-December 07


Dream Kudos: 425

Posted 09 June 2009 - 02: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 online

  • Dreaming Coder
  • Icon
  • View blog
  • Group: Expert w/DIC++
  • Posts: 4,727
  • Joined: 16-October 07


Dream Kudos: 575

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Posted 09 June 2009 - 03: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
  • PipPipPip
  • Group: Members
  • Posts: 380
  • Joined: 25-November 07


Dream Kudos: 0

Posted 09 June 2009 - 03: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 - 03:37 PM

Was This Post Helpful? 0
  • +
  • -

#16 Locke  Icon User is online

  • Treasure Hunter
  • Icon
  • View blog
  • Group: Mentors
  • Posts: 4,356
  • Joined: 20-March 08


Dream Kudos: 350

Expert In: Java

Posted 09 June 2009 - 04:34 PM

View PostPsychoCoder, on 9 Jun, 2009 - 09:25 AM, said:

Moved to Corner Cubical :)


AGH!!!!! :crazy: ;)

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: 09 June 2009 - 04:35 PM

Was This Post Helpful? 0
  • +
  • -

#17 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • Icon
  • Group: Expert w/DIC++
  • Posts: 739
  • Joined: 10-May 09


Dream Kudos: 125

Expert In: PHP, MySQL

Posted 09 June 2009 - 08:37 PM

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 ^_^)

Yours,
Shane~
Was This Post Helpful? 0
  • +
  • -

#18 onesmartguy  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 10-July 09


Dream Kudos: 0

Posted 10 July 2009 - 12:30 PM

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.
Was This Post Helpful? 0
  • +
  • -

#19 paperclipmuffin  Icon User is offline

  • WinWinWinWindows?
  • Icon
  • View blog
  • Group: Authors
  • Posts: 910
  • Joined: 16-April 09


Dream Kudos: 400

Posted 13 July 2009 - 01:19 AM

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

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


+1 :^:
Was This Post Helpful? 0
  • +
  • -

#20 NeoTifa  Icon User is offline

  • 1-800-NEO-ROXS
  • Icon
  • View blog
  • Group: Authors
  • Posts: 7,603
  • Joined: 24-September 08


Dream Kudos: 150

Posted 13 July 2009 - 05:36 AM

Who cares really?

Its quality not quantity :D
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



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