What's Here?
- Members: 340,149
- Replies: 920,517
- Topics: 154,948
- Snippets: 4,855
- Tutorials: 1,257
- Total Online: 3,862
- Members: 117
- Guests: 3,745
|
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!
Chat LIVE With a Expert
|
How do programmers count lines of code
How do programmers count lines of code
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.
Posted 09 June 2009 - 07:15 AM
My IDE/Text editor has line numbers built into it.

- apt-get install DIC.bin
-
-
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
Posted 09 June 2009 - 07:41 AM
Nykc, 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.
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.
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.
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.)
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.
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
Posted 09 June 2009 - 12:43 PM
For the record, # of lines is not a very good metric for much anything.
Posted 09 June 2009 - 12:44 PM
KYA, on 9 Jun, 2009 - 12:43 PM, said:
For the record, # of lines is not a very good metric for much anything.
I agree.
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
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).

- Dreaming Coder
-
-
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?
In any case, the wiki page on this is reasonably informative: http://en.wikipedia....e_lines_of_code
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
Posted 09 June 2009 - 04:34 PM
PsychoCoder, on 9 Jun, 2009 - 09:25 AM, said:
Moved to Corner Cubical 
AGH!!!!!
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
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~

- New D.I.C Head
-
-
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.
Posted 13 July 2009 - 01:19 AM
Nykc, on 9 Jun, 2009 - 07:15 AM, said:
My IDE/Text editor has line numbers built into it.
+1
Posted 13 July 2009 - 05:36 AM
Who cares really?
Its quality not quantity
1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|