Hacker News new | ask | show | jobs
by baddox 5768 days ago
I know I've read some seasoned Lisper insist that beyond a certain sized software project, good Lisp code will have fewer parentheses than good Java code has curly braces (owing supposedly to Lisp's potential conciseness). Of course, this could be an exaggeration or even a "no true Scotsman" argument. I haven't enough experience to know if the claim is plausible.
3 comments

Java only uses braces to denote blocks, whilst Lisp uses parenthesis for everything. Contrast:

    (if (= x 0)
      (foo x)
      (bar x))
And:

    if (x == 0) {
        foo(x);
    }
    else {
        bar(x);
    }
The Lisp code has 8 parenthesis, whilst the Java code only has 4 braces. However, the Java code also has 6 parenthesis and 2 semicolons, so in total the Lisp code only has 8 control flow tokens, whilst the equivalent Java has 12 (or 13, if you count the 'else').
That what I meant by "beyond a certain sized software project." The claim was that because Lisp can do a lot of things Java can't, Lisp will end up requiring such less code that it will have fewer parentheses than Java has curly braces. However, as another commenter mentioned, Lisp will surely have a higher parenthesis density than Java's curly brace density.
I don't know if that is literally true (I did spend quite a few years being paid to write Lisp, followed by quite a few years writing Java) but I think once you have been using Lisp for a while with a good environment the parentheses certainly feature a lot less in how you visualize the code.

I am also a Scot - if that helps ;-)

Yeah, I'm not sure, but for our purposes I just mean density. The typical line of lisp code may have 3 or 4 close-parens.