Python syntax in Lisp and Scheme

Andrew Dalke adalke at mindspring.com
Thu Oct 9 15:28:54 EDT 2003


Björn Lindberg:
> Apart from the usual problems with micro benchmarks, there are a few
> things to consider regarding the LOC counts on that site:

I wasn't the one who pointed out those micro benchmarks.  Kenny
Tilton pushed the idea that more concise code is better and that Lisp
gives the most concise code, and that Perl is much more compact
than Python.  He suggested I look at some comparisons, so I followed
his suggestion and found that 1) the Lisp code there was not more
succinct than Python and 2) neither was the Perl code.

>   * Declarations. Common Lisp gives the programmer the ability to
>     optimize a program by adding declarations to it.

While OCaml, which has the smallest size, does type inferencing....

>     since the
>     micro benchmarks in the shootout are focused on speed of
>     execution, and they are so small, all of them contains a lot of
>     declarations, which will increase LOC.

Ahh, good point.

>   * In many languages, any program can be written on a single
>     line. This goes for Lisp, ut also for C and other languages.

Absolutely correct.  Both Alex Martellli and I tried to dissuade
Kenny Tilton that LOC was the best measure of succinctness and
appropriateness, and he objected.

>   * I don't think the LOC saving qualities of Lisp is made justice in
>     micro benchmarks. The reason Lisp code is so much shorter than the
>     equivalent code in other languages is because of the abstractive
>     powers of Lisp, which means that the difference will be more
>     visible the larger the program is.

Agreed.  I pointed out elsewhere that there has been no systematic
study to show that Lisp code is indeed "so much shorter than the
equivalent code in other languages" where "other languages" include
Python, Perl, or Ruby.

The closest is
 http://www.ipd.uka.de/~prechelt/Biblio/
where the example program, which was non-trivial in size
took about 100LOC in Tcl/Rexx/python/perl and about 250LOC
in Java/C/C++.

There was a repeat of that test at
  http://www.flownet.com/gat/papers/lisp-java.pdf
which showed that the average Lisp size was 119 LOC and
277 for Java.  I eyeballed the numbers, and I'm not sure if
the counts included comments or not, so call it the same.

In any case, it implies you need to get to some serious sized
programs (1000 LOC? 10000LOC? A million?) before
the advantages of Lisp appear to be significant.

That's not saying that they are more obvious in some subdomain.
For that matter, if I want to do hardware I/O on some
memory mapped ports, it's pretty obvious that C is a good
contender for that domain.

So we're left with depending on gut feelings, guided by
(non-rigorous) observation.  Eg, observations that Python
does scale to large projects, observations that the people
who will use my code (computational scientists, not
programmers) find Python easier than Lisp and Tcl-style
commands easier than Python :(.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list