Re: New Computer Language Shootout?
- From: Slobodan Blazeski <slobodan.blazeski@xxxxxxxxx>
- Date: Fri, 20 Jul 2007 04:24:14 -0700
On Jul 20, 1:34 am, André Thieme <address.good.until.
2007.dec...@xxxxxxxxxxx> wrote:
Jon Harrop schrieb:
For example, a parser and evaluator for a simple dynamically typed
functional language with first-class lexical closures that can interpret
the following program:
let rec fib n =
if n=0 then 0 else
if n=1 then 1 else
fib(n - 1) + fib(n - 2) in
fib 35
may be written in only 49 lines of OCaml:
When making a line count then Lisp often is not the best.
This has several reasons:
In Lisp functions, variables and macros usually have longish names.
These have to fit into 80 chars wide lines. This is a style descision.
If you want to write to a file it could for example look like this in
Lisp:
(with-open-file (out "/path/to/file"
:direction :output
:if-does-not-exist :create
:if-exists :overwrite)
...)
It takes up 4 LOC and it looks like a 4 liner, while it really is just
one line. The arguments (that start with a colon ":") could well have
been compressed into a cryptic string:
(w/file (out "oco" "/path/to/file")
..)
and suddenly it looks like a one-liner.
Also other style elements will make Lisp code using up more lines.
Let's take this simple accumulator producing function:
(defun make-accumulator (n)
(lambda (i)
(incf n i)))
In some other languages the same solution could look like
fun makeAccumulator n = (i -> n inc i)
To factor out these style implications you could try to compare
the source code when it is packed. The best packers for code should be
compilers, I think.
For example you can look at the file size of a compiled OCaml function
and the file size of a (with clisp) compiled function.
André
--
Very-long-and-descriptive-names are one of the strengts that I
learned from the lisp culture and I use it in all the languages I
encounter. As soon as your programm becomes non-trivial there is more
interest with reading & understanding code than line count,
especially if there are other programmers involved or even for
yoyrself after few motnhs. For a good style namings look at :
http://www.cs.northwestern.edu/academics/courses/325/readings/names.html
from
http://www.cs.northwestern.edu/academics/courses/325/readings/
.
- Follow-Ups:
- Re: New Computer Language Shootout?
- From: Tamas Papp
- Re: New Computer Language Shootout?
- References:
- New Computer Language Shootout?
- From: Jon Harrop
- Re: New Computer Language Shootout?
- From: Mark Tarver
- Re: New Computer Language Shootout?
- From: Frank Buss
- Re: New Computer Language Shootout?
- From: Mark Tarver
- Re: New Computer Language Shootout?
- From: Jon Harrop
- Re: New Computer Language Shootout?
- From: André Thieme
- New Computer Language Shootout?
- Prev by Date: Re: Friendlier syntax
- Next by Date: Re: Friendlier syntax
- Previous by thread: Re: New Computer Language Shootout?
- Next by thread: Re: New Computer Language Shootout?
- Index(es):
Relevant Pages
|
Loading