[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Selling Lisp

I sent the following message to Paul Hasse, which may be of interest to others:

------ Forwarded Article <NORVIG.95Jan31123747@comet.menlo.harlequin.com>
------ From norvig@comet.menlo.harlequin.com (Peter Norvig)

Tom Dean has released C++ and Lisp implementations of code for a new
textbook, available for ftp from bc.aw.com.  I thought it would be
interesting to compare the lines of code for C++ and Lisp.

It turns out that the C++ implementation is 6.6 times longer then the
Lisp implementation (19534 vs 2953 non-comment lines), and uses 7.3
times more files (175 vs 24).  This is true even though (1) some of
the functionality of the Lisp implementation was left out of the C++
implementation, and (2) Dean has chosen to use a minimal subset of
Common Lisp (to aid portability and to facilitate automatic
translation from Common Lisp to Scheme) which is rather verbose.  For
example, he uses:

	(defun make-NODE (name) (list name 'OUT () ()))
	(defun NODE-label (node) (second node))
	(defun NODE-justifications (node) (third node))
	(defun NODE-justificands (node) (fourth node))

	(defun set-NODE-label (node l) (setf (second node) l))
	(defun set-NODE-justifications (node j) (setf (third node) j))
	(defun set-NODE-justificands (node j) (setf (fourth node) j))

where more idiomatic Common Lisp would replace these 7 lines with 2:

	(defstruct node
	  name (label 'out) (justifications '()) (justificands '()))

Dean did the initial design and wrote the Lisp implementation.  The
C++ implementation was done by two experienced student programmers,
who had access to the Lisp implementation and to pseudo-code, but were
presumably less well-versed than Dean in the subject matter.

I chose to compare non-comment lines rather than total lines because
each file contains a lengthy copyright notice as a comment.

Here's how I counted the lines of code:

### C++ lines, non-comment lines, files:
% cat `find . -name '*.C' -print -o -name '*.H' -print` | wc -l
% cat `find . -name '*.C' -print -o -name '*.H' -print` | grep -cv '^/'
% find . -name '*.C' -print -o -name '*.H' -print | wc -l

#### Lisp lines, non-comment lines, files:
% cat `find . -name '*.lisp' -print` | wc -l
% cat `find . -name '*.lisp' -print` | grep -cv '^;'
% find . -name '*.lisp' -print | wc -l

Peter Norvig                          
Harlequin Inc.                        Email: norvig@harlequin.com
1010 El Camino Real, Suite 310        Phone: 415-833-4022
Menlo Park CA 94025                   Fax:   415-833-4111

------ End of Forwarded Article