For Programmers: Free Programming Magazines  


Home > Archive > Java Help > January 2008 > Reliable Lines of Code Counter for Java









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Reliable Lines of Code Counter for Java
Renli

2008-01-06, 8:15 am

Hi. Newbie question? dunno. I'm trying to analyze my program but every
line of code counter I download gives me a different number, from
about 3000 to about 6000. "loc.jar" seems to say 3665, CodeAnalyzer
4152 or something, and then there's source monitor which says 3253.
CLOC gives me 4256 (but then multiplies it by a scale of 1.36.. wtf??)
then tells me I have a 3rd generation equivalent of 5788.16 lines.
Point sixteen lines? I think I am getting a headache now!

What's a programmer to do? What should I use? Thanks.

-
Roedy Green

2008-01-06, 8:15 am

On Sat, 5 Jan 2008 20:46:10 -0800 (PST), Renli
<usagi.meijin@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>What's a programmer to do? What should I use? Thanks.


You just have to be consistent.

Ideas: run the code through a formatter first so you don't get a
different count depending whether someone puts { on a line by itself.
see http://mindprod.com/jgloss/beautifier.html

count the tokens, ignoring comments. See
http://mindprod.com/jgloss/parser.html

Comments are code too. Why not just count the keystrokes where
continuous strings of spaces count as one.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Andrew Thompson

2008-01-06, 8:15 am

Renli wrote:
>Hi. Newbie question? dunno. I'm trying to analyze my program

...
>What's a programmer to do?


Don't use such simplistic methods as line counts as
any sort of analysis?

(There are some long drawn out discussions of line-count
to determine 'productivity' - I think moreso in the c.l.j.programmer
group. The usual advice is that the line count does not
amount to a useful number.)

--
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.as...-setup/200801/1

Andrew Thompson

2008-01-06, 8:15 am

Andrew Thompson wrote:
>...
>
>Don't use such simplistic methods as line counts as
>any sort of analysis?


<speculative>
Perhaps a class diagram or lint check would be a better
'metric'?
</speculative>

--
Andrew Thompson
http://www.physci.org/

Message posted via http://www.javakb.com

Daniel Dyer

2008-01-06, 8:15 am

On Sun, 06 Jan 2008 05:00:33 -0000, Roedy Green
<see_website@mindprod.com.invalid> wrote:

> On Sat, 5 Jan 2008 20:46:10 -0800 (PST), Renli
> <usagi.meijin@gmail.com> wrote, quoted or indirectly quoted someone
> who said :
>
>
> You just have to be consistent.
>
> Ideas: run the code through a formatter first so you don't get a
> different count depending whether someone puts { on a line by itself.
> see http://mindprod.com/jgloss/beautifier.html
>
> count the tokens, ignoring comments. See
> http://mindprod.com/jgloss/parser.html


Or, specifically, measure the NCSS (non-commenting source statements),
this omits whitespace, comments and isn't sensitive to whether your braces
are on new lines or not. There is a tool called JavaNCSS
(http://www.kclee.de/clemens/java/javancss/) that you could use for this.

I was looking for a decent tool for generating metrics on a Java codebase
(preferably an Ant task that would generate XML and/or HTML reports) a few
months ago. I didn't find much. I was going to write my own, but I
haven't got anywhere with it yet because it's not a particularly
interesting problem.

If you use IDEA, there is a plugin called Metrics Reloaded, which is worth
downloading just for the name.

Dan.

--
Daniel Dyer
http://www.uncommons.org
Patricia Shanahan

2008-01-06, 7:19 pm

Renli wrote:
> Hi. Newbie question? dunno. I'm trying to analyze my program but every
> line of code counter I download gives me a different number, from
> about 3000 to about 6000. "loc.jar" seems to say 3665, CodeAnalyzer
> 4152 or something, and then there's source monitor which says 3253.
> CLOC gives me 4256 (but then multiplies it by a scale of 1.36.. wtf??)
> then tells me I have a 3rd generation equivalent of 5788.16 lines.
> Point sixteen lines? I think I am getting a headache now!
>
> What's a programmer to do? What should I use? Thanks.
>
> -


There are many definitions of lines of code. Should each of the
following be counted?

* Zero length lines.
* Lines containing only spaces and tabs.
* Comment lines.
* Annotations.
* Javadoc comments.

Presumably, you have some use for this line count. You need to decide
what should count in your situation, taking into account your code
formatting. Then you need to pick a count program that, with suitable
options if applicable, counts the way that makes most sense for your
purpose.

However, beware of lines of code as a surrogate for anything else. For
example, one of the most productive ws of my professional career
resulted in a significant reduction in the number of lines of code in my
project.

Patricia
Stefan Ram

2008-01-06, 7:19 pm

Patricia Shanahan <pats@acm.org> writes:
>There are many definitions of lines of code. Should each of the
>following be counted?
>* Zero length lines.
>* Lines containing only spaces and tabs.
>* Comment lines.
>* Annotations.
>* Javadoc comments.


(This might not be directly related to the OPs question:)

A fundamental aspect of this is the »folk wisdom« mentioned
by Brooks:

»In Brooks' "Mythical Man Month", he notes a piece of
programmer folk wisdom, which is that a programmer has
roughly constant productivity measured in lines of code
regardless of the language he works in. This is the basic
argument for using high-level languages -- they let a
programmer do more with each line of code.«

http://www.j-bradford-delong.net/mo...ves/001084.html

One the other hand, when this is used as a measurement of
productivity, a more verbose programmer might seem to be
more productive, which yields the question:

»If programmer's productivity is measured in lines
of code, how do you think an array of 100 numbers
is initialized to zero?«

(Can't find the author now [I did not invent this].)

Charles Connell mentioned the following time-based metrics:

* Lines of code per day
* Lines of correct code per day
* Lines of correct, well-documented code per day
* Lines of clean, simple, correct, well-documented code per day
* Ability to solve customer problems quickly

http://www.developer.com/tech/article.php/988641

Beginners often write redundant code because they lack the
knowledge of some abstractions. When an advanced programmer
refactors such code, his productivity might be measured in a
/negative number/ of LOCs per day (when measured as the
difference of LOCs between the end and the start of a session).

Lew

2008-01-06, 7:19 pm

Daniel Dyer wrote:
> Or, specifically, measure the NCSS (non-commenting source statements),


You should not ignore comments.

--
Lew
Lew

2008-01-06, 7:19 pm

Patricia Shanahan wrote:
> However, beware of lines of code as a surrogate for anything else. For
> example, one of the most productive ws of my professional career
> resulted in a significant reduction in the number of lines of code in my
> project.


If it could be reliably and consistently measured, the sum of the lines
deleted, lines altered and lines added could serve as an order-of-magnitude
measure of productivity.

As will all such Heisenbergian metrics, awareness of the subject that they are
measured can skew the results,

The literature is rich with alternatives to KLOC (thousand lines of code)
measurement, none of which have gained traction as the One True Metric. All
have some value if used with wisdom. Yes, even KLOC.

--
Lew
Daniel Dyer

2008-01-06, 7:19 pm

On Sun, 06 Jan 2008 16:32:46 -0000, Lew <lew@lewscanon.com> wrote:

> Daniel Dyer wrote:
>
> You should not ignore comments.


It depends on what you want to measure. Ideally you would calculate
multiple metrics to give you the full picture. If you count lines of code
excluding comments and whitespace (i.e. NCSS) and then also count lines of
comments, you can calculate a comment ratio.

Unlike metrics that include comments and/or whitespace, NCSS is not
sensitive to formatting (it effectively counts braces and semi-colons).

Dan.

--
Daniel Dyer
http://www.uncommons.org
Renli

2008-01-06, 7:19 pm

On Jan 7, 12:32 am, Lew <l...@lewscanon.com> wrote:
> Daniel Dyer wrote:
>
> You should not ignore comments.
>
> --
> Lew


I agree; but I also think that comments represent an entirely
different metric that "ncss".

-
Lew

2008-01-07, 4:25 am

Daniel Dyer wrote:
> On Sun, 06 Jan 2008 16:32:46 -0000, Lew <lew@lewscanon.com> wrote:
>
>
> It depends on what you want to measure. Ideally you would calculate
> multiple metrics to give you the full picture. If you count lines of
> code excluding comments and whitespace (i.e. NCSS) and then also count
> lines of comments, you can calculate a comment ratio.
>
> Unlike metrics that include comments and/or whitespace, NCSS is not
> sensitive to formatting (it effectively counts braces and semi-colons).


Cogent and well-founded points.

When one stops to think about what really constitutes effective software, and
effective production of that software, both the usefulness and shortcomings of
these metrics should become evident.

A lot of the literature out there actually tells the truth of software
productivity. Stefan Ram cited Fred Brooks. Patricia Shanahan posed a series
of possible metrics software project management might want. I think of
seminal works like Peter DeGrace and Leslie Hulet Stahl's /Wicked Problems,
Righteous Solutions/, the Steve McConnell books, the /Programming Pearls/
series by Jon Bentley, Gerald Weinberg's books, all that stuff about Agile
Programming, and so many more.

Daniel and the others who responded sound a common theme, that we need a suite
of metrics and logged facts about software projects, and to correlate with
wisdom the information we derive therefrom.

<http://en.wikipedia.org/wiki/Fred_Brooks>
<http://en.wikipedia.org/wiki/Wicked_problem>
<http://www.poppendieck.com/wicked.htm>
<http://en.wikipedia.org/wiki/Steve_McConnell>
<http://en.wikipedia.org/wiki/Jon_Bentley>
<http://en.wikipedia.org/wiki/Gerald_Weinberg>
<http://en.wikipedia.org/wiki/Agile_software_development>

--
Lew
apm35@student.open.ac.uk

2008-01-07, 4:25 am

On 6 Jan, 13:37, "Daniel Dyer" <"You don't need it"> wrote:
> I was looking for a decent tool for generating metrics on a Java codebase
> (preferably an Ant task that would generate XML and/or HTML reports) a few
> months ago. I didn't find much. I was going to write my own, but I
> haven't got anywhere with it yet because it's not a particularly
> interesting problem.


If you are still interested in writing a project to do this you may be
able to use ideas/code from a C++ project that does a similar job for C
++. It has the strange name of cccc and may be found at http://cccc.sourceforge.net.

> Dan.
>
> --
> Daniel Dyerhttp://www.uncommons.org


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com