Archived

This topic is now archived and is closed to further replies.

AndreTheGiant

how many lines in your program?

Recommended Posts

AndreTheGiant    329
I frequently hear people talking about writing 1000 lines of code for this project or 10 000 lines for that. First of all, 1000 lines isnt that much is it? I could be wrong, but isnt that just a couple of functions, in maybe 2 or 3 source files? Anyway, Im using vc++ and i have about 30 files in my current project (15 header and 15 cpp approx). Is there an easy way to get vc++ to count all the lines in my project so i know how many lines i wrote? Also, when people say 1000 lines of code, does that include whitespace and really trivial code? Does it include comments? for example,

#include <iostream.h>
#include <fstream>

using namespace std;

int main ( )
{

  // create a read/write file-stream object on tiny char

  // and attach it to the file "filebuf.out"

  ofstream out("filebuf.dat",ios_base::in |ios_base::out);
this is technically 12 lines, but there is only really 1 line of ''actual'' code if you ask me. Would this count as 12, or 1 or something else? If vc++ has a counting functionality, does it cound this as 12 or 1 or something else? thanks!

Share this post


Link to post
Share on other sites
C-Junkie    1099
I'd count it as 5...

edit: but as for how people usually count their programs, I usually round down a bit. for instance....

~/Projects/timbirc/src$ cat * | wc -l
4016


I've got a small two thousand line project...


[edited by - C-Junkie on August 9, 2003 4:23:18 PM]

Share this post


Link to post
Share on other sites
En Dum En    100
I don''t believe there is an official standard about this since it''s not a very useful way to measure code but I''d simply count all lines including comments, whitespaces and preprocessor definitions.

Share this post


Link to post
Share on other sites
Maega    707
Why would you not count "trivial code"?

In my experience, without that "trivial code" your program wouldn''t work

Share this post


Link to post
Share on other sites
cmdkeen    166
http://www.wndtabs.com/ provides a nice little line counting plugin for visual studio 6/7.

Jan Rehders / sheijk. Velox3D programmer at [url=http://www.sechsta-sinn.de]6S[/url]

Share this post


Link to post
Share on other sites
civguy    308
Token count would be much more interesting than line count.

int main() { cout << "hello world" << endl; }

12 tokens

int main()
{
cout << "hello world" << endl;
}

12 tokens

Share this post


Link to post
Share on other sites
python_regious    929
Does it really matter? My current project is about 25000 lines at the moment, woohoo, yay for me... *sighs*. It''s the quality of code you write not the quantity.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
antareus    576
No python you fail to realize that you NEED to know the number of lines in your project! What else would you put in your sig besides esoteric metal lyrics?

Share this post


Link to post
Share on other sites
PHRICTION    122
quote:
Original post by python_regious
Does it really matter? My current project is about 25000 lines at the moment, woohoo, yay for me... *sighs*. It''s the quality of code you write not the quantity.


Agreed. That said, I probably would count comments. Comments are an important part of writing code.

Share this post


Link to post
Share on other sites
shadowman13131    122
The only ACCURATE way of counting lines in my opinion would be to count the compiled assembly lines of code. There ya go. But, since chances are you didn''t write everything in assembly, and the compiler would write the assembly for you then, well. You''re screwed. You wrote 0 lines of code. Have a nice day.

Share this post


Link to post
Share on other sites
AndreTheGiant    329
quote:

Does it really matter? My current project is about 25000 lines at the moment, woohoo, yay for me... *sighs*. It''s the quality of code you write not the quantity.

Death of one is a tragedy, death of a million is just a statistic.



No i guess it doesnt really matter. I realize that this is not the most accurate way to count how much effort/time has gone into a project since you can accomplish quite a bit or almost nothing with one line of code, depending on how you program. But what I want to know is, how did you get that number? 25000 is a lot of lines to be counting by hand. And unless the ENTIRE program is in one source file, I dont know of any easy way to count all the lines in a project.

Besides, i think its safe to say that although different people program very differently, most people are pretty consistant (or they should be at least). So while Joe''s 20000 lines might actually be either more or less work than Bob''s 10000 lines, Its probably more or less true that Joe''s 20000 lines is roughly twice as much work as Joe''s 10000 lines from a different program he wrote last year.

Share this post


Link to post
Share on other sites
antareus    576
Here is a famous algorithm for calculating approximate line counts in ANY IDE:

for every source file
add the number of lines, (rounded off to the nearest convienent digits), to a count

And IMO, less is more with respect to code length. Hence comparisons are useless.

Share this post


Link to post
Share on other sites
civguy    308
quote:
Original post by antareus
And IMO, less is more with respect to code length. Hence comparisons are useless.
Weird reasoning. LOC could be just as well be used to compare who has the least amount of code for same amount of features.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
> First of all, 1000 lines isnt that much is it?

It depends. It''s not how you count it, but how you use this information that''s important.

LOC is mostly used for anticipating the amount a work a team will need on any given project of the same scope and nature of the ones it already did. Even that is dubious as tools change all the time. For example, Softimage|3D v4 weighs around 3M lines of C code, while Softimage|XSI is closer to 10M lines of C+/STL code. Radical changes in a software system are very difficult to plan for, and more so if there are radical changes in technology and core architecture. Incremental releases are much much easier to plan, though. As for games, it''s mostly radical change all the time (unless you do ports), so any new title is hard to pin down exactly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
People that "count lines" in their code are often the first people to be fired because they have no programming skills.

You should worry more about whether or not your program addresses the situation you were presented with.

Share this post


Link to post
Share on other sites
antareus    576
True story:
I didn''t know bit shifting for some compression project I was doing (Huffman), and so to avoid it I converted the number into a string of binary digits and pulled the bits off like that. Meanwhile my friend used bit shifting like I should have.

I wrote more code than he did. Except, his was clearer, and faster.

Line counts are archaic and meaningless. "My project is 2,000 lines." BIG DEAL . Comparing line counts gets you nothing. 2,000 lines is a lot for a higher level language like C# where the CLR provides most of what you need to make apps. Meanwhile, at a place like Gamedev, 2,000 is not a lot for C++. (when you have a lot of users rewriting STL containers for reasons like "I don''t like how vector isn''t named CVector!!!")

Aim for clarity.

Share this post


Link to post
Share on other sites
RapidStunna    122
quote:
I frequently hear people talking about writing 1000 lines of code for this project or 10 000 lines for that. First of all, 1000 lines isnt that much is it? I could be wrong, but isnt that just a couple of functions, in maybe 2 or 3 source files?


1000 IS a lot. It''s more than a couple of functions, or SHOULD be haha ! You''d be lucky to write 1000 lines of code in a day.

Lines of code should NOT include comments. Yes, they are important, but when you measure, do not include them. This is because comments are exactly that, just comments. You''ll probobly end up thinking "Wow I''m writing a lot of code!" until you actually take a look at how much of that is comments and whitespace. In general, it''s better to say "My program is 1000 lines of code, excluding comments and whitespace" than "My program is 2000 lines of code, but that includes both comments and whitespace". It just doesn''t accurately reflect your progress.

---
Brent Gunning | My Site

Share this post


Link to post
Share on other sites
python_regious    929
quote:
Original post by AndreTheGiant
25000 is a lot of lines to be counting by hand.



Indeed. I''m not that nuts. I wrote a program that grabbed all the h and cpp files in a folder and counted the lines in it. Only wrote it because I was bored and a mate wanted it.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
Choff    122
Some software engineering methods use a technique of counting semi-collens. (My company uses this method) It''s not 100% accurate but it''s close enough. Whitespace and comments are insignificant for the perposes of counting code. Even though the time spent on commenting is importaint.

Counting lines of code is only useful if you work in places that record historical data, like lines of code and man-months.

This is useful information when gathered over time. It can give you insite into your programming process and measure performance.

I''m guessing in game companies and independent projects this would be less of an issue.

Share this post


Link to post
Share on other sites
Cedric    158
Most of my projects that I''ve looked at we''re in the 1,000 - 10,000 range (including comments). Once I reach a few thousand lines, I start looking heavily into creating components that I can reuse eventually. And I end up not including the functions I "generalize" because they are no longer part of my project per se.

Much like a function shouldn''t be too long, a project should often be broken into independant chunks.

Cédric

Share this post


Link to post
Share on other sites