Count lines of source code

michael "krill-man" lee mikey at ontek.com
Sat Feb 23 06:14:04 AEST 1991


In comp.lang.c,comp.sources.wanted, 
  snk at bae.bellcore.com (Samuel N Kamens) writes:
| 
| Hi,
| 
| Does anybody have or know of a routine that will count the 
| actual statements in a file of C source code?  I want to
| eliminate comments, and compress multi-line statements
| to register as a single statement.

grep '[;}]' <filenames> | wc -l

I would stress that using any sort of line counter as a measure
of programmer productivity is likely to backfire.  If anything,
there is an advantage in maintainability for a program which is
more compact. Fewer source lines often result in smaller object
files, which in turn taxes memory resources to a lesser degree.

There are a number of metrics one can apply to source:

  lines per function
  ratio of source / object
  ratio of comments / source
  characters per line

All are meaningless.  Compile the code and see if it works.  As
you might have guessed, this subject is one of my pet C peeves.

         the krill, poorly adjusted paragraphs is the other one



More information about the Comp.lang.c mailing list