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

language comparisons (was Re: call/cc)

Paul Graham writes:
> I think these numbers are a little misleading because
> mandatory whitespace, though an expressive element 
> (i.e. the meaning of the program changes if you take 
> it out) is not counted as a token. What would the numbers
> be if you counted mandatory whitespace?  

I wrote the original under the hypothesis that, to a first
approximation, mandatory whitespace doesn't make a program take longer
to read (partly because it's usually in places where programmers put
optional whitespace when it's not mandatory), but non-whitespace
syntactic tokens do.

Here are the same programs with no unnecessary whitespace; the
ordering is unchanged, except that Lisp is considered relatively more
verbose and the stricter FORTH program is considered far more verbose.
That's pretty much what you'd expect.

Curl: {{proc{x,y}{return x+y}}3,5}    20 elements (I think; thanks Chris; 
                                                     19 tokens)
Lisp: ((lambda(x y)(+ x y))3 5)       20 elements (thanks Paul)
Perl: sub{$_[0]+$_[1]}->(3,5)         18 elements
JavaScript: function(x,y){return x+y}(3,5)   18 elements
FORTH: marker foo 3 5 :noname + ; execute foo   17 elements
Smalltalk: [:x :y|x+y]valueWithArguments:#(3 5)
                                      17 elements
Python: (lambda x,y:x+y)(3,5)         16 elements (thanks Jeremy)
OCaml: (fun x y->x+y)3 5              14 tokens  (actually 11 tokens, not 10)
Haskell: (\x y->x+y)3 5               13 tokens  (also actually 11, not 10)
FORTH: 3 5 :noname + ; execute        11 elements
PostScript: 3 5{add}exec               7 elements
dc: 3 5[+]x                            7 elements