[comp.software-eng] C code metrics

bradlee@cg-atla.UUCP (Rob Bradlee X5153) (06/28/88)

Request for Help:

I've recently been reading DeMarco's "Controlling Software Projects"
(Yourdon Press 1982), and am now interested in adding some metrics 
to our project.  However, his metrics are designed for EDP projects 
written in COBOL.  We have an interactive system written in C and 
running UNIX.  Can any net readers offer advice about or tools for 
measuring the following:

	Code Volume
		Past attemps to measure the size of code have used 
		number of lines.  However, this appears to be pretty
		inaccurate.   DeMarco suggests that counting the
		number of operands and operators and multiply by
		the log(base 2) of the number of unique identifiers
		is a much more accurate measure.  Anyone have a
		program to parse C code and do this?  What about
		including .h files and macros?

	Code Quality
		DeMarco suggests analysing code by counting the
		number of entry and exit points from routines,
		looking for GOTOs, etc.  Anyone have a program
		that could parse C code and at least give
		some indication of relative complexity of
		different modules and perhaps hightlight
		areas of code that might profit from a code
		code review?
		

I'm looking both for information explaining how to judge the size and
quality of C code, and also for any tools that will automatically
perform some analysis.  Send me email, and if I get any good info I'll
summarize to the net.  Thanks in advance.


-- 
Rob Bradlee  w:(617)-658-5600 X5153  h:(617)-944-5595
Compugraphic Corp.	    ...!{ima,ulowell,ism780c}!cg-atla!bradlee
200 Ballardvale St.
Wilmington, Mass. 01887           The Nordic Way: Ski till it hurts!

twb@hoqax.UUCP (T.W. Beattie) (06/30/88)

In article <4820@cg-atla.UUCP>, bradlee@cg-atla.UUCP (Rob Bradlee X5153) writes:
> Request for Help:
> I'm looking both for information explaining how to judge the size and
> quality of C code, and also for any tools that will automatically
> perform some analysis.

Earlier this year CACM had an excellent article about an NPATH complexity
metric.
It suggests that the complexity of the code (levels of nesting, etc) are
a useful measure of the quality of the code and a particularly good measure of
the maintainability of the code.

I particularly like this metric because it seems difficult to make the
code worse by decreasing the metric.
Many other metrics encourage bad coding practices.

Tombo.

warren@psu-cs.UUCP (Warren Harrison) (07/02/88)

> Request for Help:
> 
> I've recently been reading DeMarco's "Controlling Software Projects"
> (Yourdon Press 1982), and am now interested in adding some metrics 
> to our project.  However, his metrics are designed for EDP projects 
> written in COBOL.  We have an interactive system written in C and 
> running UNIX.  Can any net readers offer advice about or tools for 
> measuring the following:
> 
> 	Code Volume
> 		Past attemps to measure the size of code have used 
> 		number of lines.  However, this appears to be pretty
> 		inaccurate.   DeMarco suggests that counting the
> 		number of operands and operators and multiply by
> 		the log(base 2) of the number of unique identifiers
> 		is a much more accurate measure.  Anyone have a
> 		program to parse C code and do this?  What about
> 		including .h files and macros?
> 
> 	Code Quality
> 		DeMarco suggests analysing code by counting the
> 		number of entry and exit points from routines,
> 		looking for GOTOs, etc.  Anyone have a program
> 		that could parse C code and at least give
> 		some indication of relative complexity of
> 		different modules and perhaps hightlight
> 		areas of code that might profit from a code
> 		code review?
> 		
> 
> I'm looking both for information explaining how to judge the size and
> quality of C code, and also for any tools that will automatically
> perform some analysis.  Send me email, and if I get any good info I'll
> summarize to the net.  Thanks in advance.
> 
> 
> -- 
> Rob Bradlee  w:(617)-658-5600 X5153  h:(617)-944-5595
> Compugraphic Corp.	    ...!{ima,ulowell,ism780c}!cg-atla!bradlee
> 200 Ballardvale St.
> Wilmington, Mass. 01887           The Nordic Way: Ski till it hurts!

Look into PC-METRIC from SET Laboratories [503-289-4758].  Does Halsteads
Software Science (the operator/operand strategy you refer to) and Cyclomatic
Complexity.  Versions for C, Pascal, Modula-2, COBOL, FORTRAN, etc.  It was
reviewed in this month's Computer magazine from IEEE.

--- I admit I work for them sometimes ... but I'm just answering the
guy's question ---

cl@datlog.co.uk (Charles Lambert) (07/06/88)

In article <4820@cg-atla.UUCP> bradlee@cg-atla.UUCP (Rob Bradlee X5153) writes:
>Request for Help:
>
>I'm looking both for information explaining how to judge the size and
>quality of C code, and also for any tools that will automatically
>perform some analysis.  Send me email, and if I get any good info I'll
>summarize to the net.  Thanks in advance.

Can we keep this discussion in the open, please?  I know it gets hashed over
fairly regularly but it is important and perspectives are changing all the
time.  At the moment,  there are several initiatives in the UK to promote
better engineering practices in software;  we cannot engineer what we cannot
measure,  so any discussion of methods is useful.

Charlie

bdr@neti1.uucp (Brian Renaud) (07/13/88)

In article <816@dlhpedg.co.uk>, cl@datlog.co.uk (Charles Lambert) writes:
> In article <4820@cg-atla.UUCP> bradlee@cg-atla.UUCP (Rob Bradlee X5153) writes:
> >Request for Help:
> >
> >I'm looking both for information explaining how to judge the size and
> >quality of C code, and also for any tools that will automatically
> >perform some analysis.  Send me email, and if I get any good info I'll

I have some programs (shell/awk/C, etc.) which provide some metrics
for C programs.   As I remember, they consist of:

   line counter - print actual lines of code (useful for COCOMO modeling)
                  as well as blank lines, number of comments, comment lines

   halstead     - provide various software science metrics, based on Halstead's
                  work

   mccabe       - program complexity analyzer, based on McCabe, etc.

I also have some rather arcane scripts which will run these tools on
a specified set of programs and produce some flat files containing only
the metrics I have found to be statistically significant.  (You may find
that these metrics are not right for you, I only analyzed two 30K DSI
projects.)

If you would like these let me know.  Email is the best way to reach me,
since my access to this news feed is rather shaky.

Brian
--
Brian Renaud	bdr%huron.uucp@umix.cc.umich.edu
		umix!huron!bdr
-- 
Brian Renaud      bdr%huron.uucp@umix.cc.umich.edu
Huron Systems     {umix,neti2}!huron!bdr