Hi,
could someone help me by telling, how to find total number oflines in the code. The detail is like, I have a project which contains a number of files. Each file has different number of lines as code. I want to know is there any easy way/shortcut/options for finding the total number of line for the whole project.
I also checked the .M51 (map) file, it is indicating the number of lines in sequence from 1 onward for each function, but its really hectic to count for each and then add. Similarly editor is also showing the lines along the code inthe file but again its laborious to count and then add.
Looking for clever response.
Regards Asad
The big question here is why you want to know the number of source code lines, since it really isn't a very important figure. The number of source code lines compared to the number of lines with real source will vary a lot depending on amount of commends and indentation style. Remember that just using "sneaky braces" where the opening brace is on the same line as the control line compared to the indentation styles where the opening brace is on its own line can represent a difference of many thousand lines of code.
If your source are in a separate directory or subtree, then you can download and use the wc (word count) program.
A number of IDE have plugins for showing line counts, so if you download Code::Blocks you could use it with the code statistics plugin and it will then use the Code::Blocks project file to know what source files are part of the project - and will also check number of empty lines, number of lines with only code or only comments and number of lines with both code and comments. Obviously, it will not know if the comments are meaningful or not, so the metrics are not really meaningful.
I got the same question 'Why there is a need for numer of lines of code' while searching online before posting here. Thing is, I need to calculate the software quality based on some calculaitons as used in my company, thats why I am asking this question. What I did, I just open the .lst files for each of the code file and then see the last line number of each file, and add together. Is it right? But I really appreciate your reply, thanks for that!
No - code metrics that only looks at the number of source lines is even worse than a code metrics that somehow tries to analyze the contents of the files.
How would a twice as large program get a different "quality" just because it is twice as large and contains twice as many source lines?
Code quality and number of source lines have extremely low correlation. You can have a 100-line program with extremely poor code quality and a million-line program with extremely good code quality.
And if including amount of comments in the code - pasting all documentation into the code doesn't make a big difference on the code quality compared to having the same documentation in separate documents. All it does is make it a slightly bit easier to update the documentation when the code is changed - while at the same time stops the developer from using graphical tools for the documentation since it suddenly got limited to text-only.
If you really do want to compute any code metrics, you should at least look at some tools that just looks at the source code and tries to evaluate the complexity of the code. Average and max size of functions. Average amounts of statements / function. Average amount of conditions in conditional statements. Average amount of nesting. Average and max number of symbols/source line (obviously excluding white and comment lines) That kind of metrics can at least be said to somehow affect how fast a developer can read the code and pick up the relevant structure, and does tell a bit about the number of symbols the developer needs to keep in his head when trying to modify the code.
Number of source lines can't be used for code quality. And it can't be used as metric for salary. It would actually be better to define a standard compiler and standard compilation settings and instead use the size of the binary as metric. The size of the generated binary would at least change with code density.
"I need to calculate the software quality based on some calculaitons as used in my company"
If your company requires it then, surely, they must have established ways to do it??
But simply counting source lines gives absolutely no indication whatsoever of software quality!
At the very least, you need to separately count both "code" and "comment" lines.
But this is still an almost useless measure - since it counts only quantity and cannot tell anything about quality!
Maybe this will help...
www.softpedia.com/.../Danjou-Line-Counter.shtml
Jon
would be to make a file glob.q and copy each and evey module into it
basing code metrics on line count is silly. I have seen awful code in 50 line modules and excellent code in 5000 line modules
Erik
Indeed!
Quite often, an unnecessary terseness is found in nasty code
"Quite often, an unnecessary terseness is found in nasty code"
Which is why code complexity is a bettery metric than number of source lines. Who likes an if statement with three &&, seven || and maybe one or more bit operators thrown in for measure?
The problem is that it is so easy to think about source line count that lots of people put that at the top of their list when they decides that they need to think about measuring code quality. But the first thing that comes to mind isn't always the best thing.
To all respected replier,
I understand that simple line count is not a good measure for software quality. My intention was to count the number of lines (separately for comments, code, blank) and then use the code lines only in my calculation (notice that I am not using the line count directly/only for software quality), instead I am using it in my calculations. I appreciate all genius replies. Thanks.