[Shootout-list] LOC

Jon Harrop jon@ffconsultancy.com
Sun, 1 May 2005 01:43:09 +0100


I'm just perusing the shootout and am noticing lots of dubious LOC counts.

For example, spectralnorm in D is 52 LOC but is counted as 30 LOC:

http://shootout.alioth.debian.org/sandbox/benchmark.php?test=spectralnorm&lang=dlang&id=0&sort=fullcpu

I only get 30 LOC if I ignore braces. I appreciate that (assuming this is 
deliberate) there is a valid debate here but, personally, I'd like say that I 
believe coding efficiency is a strong function of the amount of code you can 
see on the screen at any one time and, consequently, the verbosity of 
unnecesary braces in such languages is a major hindrance.

Certainly, I get much less information out of a page of C++ in a big program 
than I do in OCaml, because C++ code all looks very similar whereas OCaml 
code varies enormously, making it much easier to navigate.

Simply reformatting heapsort in D using a denser but still common format, the 
LOC count (including braces) is 51 instead of the attributed 43. So, I 
suggest that authors are encouraged not to put opening braces on new lines 
and that all code lines are counted.

For example, instead of writing:

  if (i == 0)
  {
    j += 1;
  }

I'd write:

  if (i == 0) ++j;

which is shorter than the above even if braces are ignored.

If the counter argument is that LOC is trying to measure the amount of typing 
then shouldn't we be measuring bytes instead of lines?

Also, I seem to recall some criteria that definitions must be split between 
lines. I'd rather use whatever style is most natural in each language. For 
example, I see nothing wrong with code like:

  double a=0, b=1, c=2;

in C++, or:

  let a, b = 0., 1. and c = 2. in

in OCaml. However, many programs (such as OCaml's harmonic) split definitions 
across multiple lines, which is unusual in OCaml programming. I suspect this 
is simply a case of asking authors to change their coding style.

I think LOC is a great measure. Not ideal, of course, but much better than 
anything else I can think of. So I'd like to see more representative LOC 
counts on the shootout.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists