views:

48

answers:

3

I am taking a software engineering class right now. Our assignment is to evaluate Mozilla's Thunderbird. Our assignment is to evaluate the size of Thunderbird. One metric that we need to use is the number of lines of code in the project. (Lines of code meaning not including comments or new lines).

Is there a standard way to find the number of lines or am I better off just cracking out a script to do this?

I think that I could do something like this:

# remove all comments
find -name *.java | \
sed "/\/*/,\*\// s/.*//g | \ # remove multiline comments
sed s/\/\///g # remove single line comments

# count not empty lines
find -name *.java | grep -c "<character>"

But I would need to do that for each file type. It seems like there should be some utility that does that already. (something mac/unix compatible would be preferable).

+1  A: 

Use CLOC.. it is written in Perl and it supports almost every programming language, it's easily configurable and very fast.

Jack
Worked like a charm.
sixtyfootersdude
A: 

The ohloh.net website uses a nice LOC calculator for their stats, which is freely available:

https://www.ohloh.net/p/loc-calculator

jkramer
+1  A: 

One of my favorite tools to count SLOC is cloc, written in Perl. Without any extra configuration on your part, it will tell you the number of blank lines, the number of commented lines, and the number of source lines over an entire tree of source files. It breaks down the numbers by file extension as well.

Mark Rushakoff