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!
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.
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.
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.)
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.
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: 9 Jun, 2009 - 11:53 AM
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
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).
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
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
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 )
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.