Newsgroups: alt.lang.design,comp.lang.c++,comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!europa.eng.gtefsd.com!news.mathworks.com!zombie.ncsc.mil!admii!lhc!lhc!hunter
From: hunter@work.nlm.nih.gov (Larry Hunter)
Subject: Re: Comparing productivity: LisP against C++ (was Re: Reference Counting)
In-Reply-To: nmein@bifrost.otago.ac.nz's message of 20 Dec 1994 01:05:53 GMT
Message-ID: <HUNTER.94Dec20152915@work.nlm.nih.gov>
Followup-To: alt.lang.design,comp.lang.c++,comp.lang.lisp
Sender: news@nlm.nih.gov
Reply-To: Hunter@nlm.nih.gov
Organization: National Library of Medicine
References: <19941203T221402Z.enag@naggum.no> <BUFF.94Dec15103904@pravda.world>
	<D0xAIp.3Dn@rheged.dircon.co.uk> <vrotneyD11MDv.Ks7@netcom.com>
	<vogtD12y8D.HLL@netcom.com> <3d5alh$6j7@celebrian.otago.ac.nz>
Date: 20 Dec 1994 20:29:15 GMT
Lines: 44
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:104242 comp.lang.lisp:16115


Nick Mein posted the following challenge:

   Anyway, I found the claims [that lisp is 2-10x more productive than C]
   rather surprising, so here is a challenge. The following toy program
   loads a 256x256 8 bit grayscale image from a file, inverts it, and saves
   it to another file. I consider myself to be an intermediate-level C++
   programmer. The program took me an hour (almost to the minute) to design,
   code, debug and test (Ok, I didn't test it very much).  I look forward to
   seeing the previous posters' Lisp implementations of the same. It should
   only take them 6 - 30 minutes to knock them together, less if they are
   reasonably experienced in Lisp.

I am reasonably experienced in lisp.  The following program took me 2
minutes and 49 seconds to design, code, debug and test.  (I tested it about
as much as you did -- it runs fine on a single example).  Most of that time
was spent looking up read/write-byte in the manual because I wasn't sure it
did exactly what I wanted -- it does.

I guess LISP is more like 20x more productive.  And much easier to read,
understand and debug.


;; This reads a file of (height * width) 8 bit values, inverts them, and
;; writes them to another file.  It will signal errors in pretty much the same
;; situations that the C program will.

(defun invert (infile outfile &key (height 256) (width 256))
  (with-open-file (in infile)
    (with-open-file (out outfile :direction :output)
      (dotimes (x height)
	(dotimes (y width)
	  (write-byte (- 255 (read-byte in)) out))))))


--
Lawrence Hunter, PhD.
National Library of Medicine
Bldg. 38A, 9th floor
Bethesda. MD 20894 USA
tel: +1 (301) 496-9300
fax: +1 (301) 496-0673 
internet: hunter@nlm.nih.gov
encryption: RIPEM via server; PGP via "finger hunter@work.nlm.nih.gov"
