News for hackers. Stuff that matters.
Re:A regular expression matcher in 19 lines of Clojure by drallison on Sunday October 16, 2011 @12:56PM (#3117674)
LOC (Lines of Code) is not a good characterization of the quality of code; clarity and understandability is. The Clojure implementation is pretty nice on those counts.

The LOC measure may be important when, for example, the goal is to show the number of operations to be as small as possible.

Re:A regular expression matcher in 19 lines of Clojure by gruseom on Sunday October 16, 2011 @05:55PM (#3118414)
LOC (Lines of Code) is not a good characterization of the quality of code

Actually it is. Or at least it's the best we have. When it comes to anything you can measure, the evidence points to program length as the best predictor of quality of code. And LOC is, for better or worse, the standard metric for code size.

We had a whole thread on HN about this a month ago. Specific studies are cited there. http://news.ycombinator.com/item?id=3037293

Speaking of which, someone later told me that Chapter 27 of McConnell's Code Complete cites studies according to which bug count grows as a mild exponential function of code size. I don't have that book handy. If anyone does, can they look at Chapter 27 and tell us what it says?

Re:A regular expression matcher in 19 lines of Clojure by arohner on Sunday October 16, 2011 @11:33PM (#3119069)
My edition is copyright 1993. In Chapter 21.3, they cite Capers Jones 1977 "Program Quality and Programmer Productivity". (Couldn't find a handy link online, appears to be http://www.amazon.com/Program-quality-programmer-productivit...)

They report the following table

    Project Size (LoC)       Error Density (Bugs / kLoC)
    0-2k                     0-25
    2k-16k                   0-40
    16k-64k                  0.5-50
    64k-512k                 2-70
    512k or more             4-100
So yes, the error density increases with LoC.
Re:A regular expression matcher in 19 lines of Clojure by dewitt on Sunday October 16, 2011 @03:55PM (#3118127)
Thanks, drallison. Generally speaking I agree, LOC alone is not a great metric of code quality, though it does roughly map to fewer places for bugs to be introduced when coding in the large, which is rarely a bad thing (though irrelevant for something like this).

In this case, I decided to implement it in a lisp after noticing that Pike's algorithm worked by consuming a character at a time off of both the pattern and the input text, lending itself naturally to a functional recursive implementation. Pike's version in C does this by advancing pointers, but it spoke equally well to an idiomatic car/cdr approach in a lisp (the recur/first/rest pattern you see in matchhere).