Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uwm.edu!linac!att!princeton!pucc!EGNILGES From: EGNILGES@pucc.Princeton.EDU (Ed Nilges) Newsgroups: comp.software-eng Subject: Re: Counting semicolons (was: Re: WANTED: "C" code line counter program) Message-ID: <12594@pucc.Princeton.EDU> Date: 16 Mar 91 15:24:00 GMT References: <1991Mar15.231326.972@jade.uucp> Reply-To: EGNILGES@pucc.Princeton.EDU Organization: Princeton University, NJ Lines: 92 Disclaimer: Author bears full responsibility for contents of this article In article <1991Mar15.231326.972@jade.uucp>, jameson@jade.uucp (Kevin Jameson) writes: >If the author figured that something (semicolons, brackets, partial boolean >expressions, etc) was worth putting on a line by itself when the code was >written, wouldn't it be reasonable to count it as a distinct line of code? > >Surely something like this > >if ((some-long-condition1 > && some-other-long-condition2) > || third condition) { > ...; > ...; >} > >should count as more lines of code than something like this: This is one of the few sensible remarks on this issue I've seen (other than my own, of course). While the facts remain that: * "Line of code" is not a meaningful concept in a free-form language like C * "Statement" as precisely defined by the Backus-Naur Form definition of the language is the only meaningful entity to count (if, like that character in Sesame Street, you Must Count) * "Measuring complexity" is suspect you are right that some sort of meaningful complexity of intent is shown by spreading a complex if conditional over a couple of lines of code. But then what is more complex? if ( logical_cond_1 || logical_cond_2 && logical_cond_3 ) ... or if ( logical_cond_1 || logical_cond_2 && logical_cond_3 ) ... The programmer of the second example has used more lines of code...but has, I think, more perspicuously expounded the intent of her code. She places the major operator on a line by itself, and displays the fact that the logical AND has higher priority than the OR by keeping it on the same line as its operands. Yet a "lines of code" metric would score the first example as being simpler and (as we all know) Simplicity is Good. The only responsible metric is not psychological, it is mathematical: it is counting statements according to the strict Backus-Naur Form definition of the language. And to avoid scoring { a = b; } /* Two statements: an assignment & a compound */ as having more statements than a = b; /* One statement: an assignment */ you must do what an optimizing compiler does and detect code that adds nothing to the "real", executable program...not only compound statements with zero or one inner statements but also unreachable "dead" code. But even if you do not do what an optimizer does and your statement counter counts dead code and useless compounds, your metric is consider- ably superior to any pseudo-clever one-line sed or awk rune. Why is it so darn important to get a "good" metric (and where's the meta-metric that tells me what's better? just asking.) Because, dammit, you are not really measuring software. You are measuring people. +--------------------------------+ Edward G. Nilges | Child support, tax-deductible | Princeton University | to payer AND receiver: an idea | Information Center | whose time has come. | Bitnet: EGNILGES@PUCC +--------------------------------+ (609) 258-2985