Standard/Proper way of counting lines of code

metrics

How should I count the lines of code in a project?

In C++ for example, should I count the lines of the header files with my class definition? Should I count the header of a (non standard) library I am linking against?

In Qt (or any other GUI framework), should I count the lines of the form's design?

Should I count the Makefile too?

I ask because it is a simple way to measure the size of the project and/or effort involved. Even though a GUI file is not code per se the programmer might have spent hours doing it.

EDIT Most of you did not understand the question and/or are assuming that I want to use the magical number of LOC as the ONE AND ONLY metric to rate a project or even a day of work.

I consider a negative LOC day a very nice day. It means I've somehow managed to understand and model the problem better and more efficiently. Comments like "Why do you need this" are not interesting.

Like it or not, the number is out there, Wikipedia says Windows XP is rated at 45M LOC, Linux 2.6.35 at 13.5M, I could go on.

Maybe I could have asked better.

Anyway, my original intent was to know how those numbers in Wikipedia were calculated and not the subjective nature of them.

I found this in a MSDN blog, very useful as it shows how VS2008 does it:

enter image description here

Best Answer

For the most part, it doesn't really matter as long as you have a standard and are consistent among projects in the same programming language. You should generally create a document that explains how to count source lines of code and how to configure any tools that you use to use this method.

In C++ for example, should I count the lines of the header files with my class definition?

I would. You did write them after all, and they are used in the build process of your software.

Should I count the header of a (non standard) library I am linking against?

Yes, you can, if you are tracking code reuse. If you have the capability to count lines of code from other projects (either your own or open-source projects), you can consider that code reuse and use it when computing various reuse-related metrics.

In Qt (or any other GUI framework), should I count the lines of the form's design?

If you wrote them, I say yes. If they were automatically generated, then perhaps. If you do it once, you should do it consistently. Perhaps you want to consider counting generated code separately than hand-written code.

Should I count the Makefile too?

I would say no, as it's a supporting tool and not part of your built application. Again, going back to the GUI framework question, if it's autogenerated, perhaps you want to count it separately. Or perhaps you want to count "build scripts" separately and include things like Makefiles, Ant scripts, and so forth.

Related Topic