Live data from Hacker News

Lisp has too many parentheses...

symbo1ics.com

61–70 of 81 posts

Re: Lisp has too many parentheses...

#61
Those who keep going on and on about parentheses in Lisp should try Haskell, which is basically* Lisp, except everything has one argument and is left associative. This simple rule removes a TON of parens. Add in the $, . operators and a bunch of other potential parentheses are eliminated.

*Except also that Haskell is typed and does not include code quoting/eval. But that's what Template Haskell is for :)

Re: Lisp has too many parentheses...

#62
post #8

This argument/response comes up every time.... Argument: "Lisp has too many parentheses. It's unreadable." Response: "It's conceptually elegant that everything is parentheses." This doesn't address the real point -- you can't read it well. You do get advantages for macros and symbolic processing. But the cost in readability is still there.

It's not a problem at all, there is zero readability cost to all of those parens. Nobody with any experience coding lisp has any trouble reading it. Personally, I find lisp code to be considerably easier to read than other languages that I otherwise prefer.

Re: Lisp has too many parentheses...

#63
post #38

I've posted this here before, I'll post it again: http://img264.imageshack.us/img264/1397/lispnd7.png In practice, I don't find it has many more parens or angle-brackets than, say, C++ or Java. Considering (), {}, and in those two languages, I'd bet Lisp wins.

I spent maybe five years being paid to write Lisp code in the early '90s and I can remember what a lot of the code looked like and, just your like that image, I really don't recall the parens that distinctly.

Re: Lisp has too many parentheses...

#64

Anyone manage to build a Lisp that used semantic indentation (like Python)? You could make it optional and just have it function as a preprocessor that generates the real thing.

Removing parentheses from the syntax removes the notion that lisp programs are lists of lists.

You can play around with significant whitespace all you like, but you have lost the simple representation of a list. How many hideous grammar hacks will you add to get this back?

Re: Lisp has too many parentheses...

#65

Those who keep going on and on about parentheses in Lisp should try Haskell, which is basically* Lisp, except everything has one argument and is left associative. This simple rule removes a TON of parens. Add in the $, . operators and a bunch of other potential parentheses are eliminated. *Except also that Haskell is typed and does not include code quoting/eval. But that's what Template Haskell is for :)

Except that I find myself adding tons of parens to my haskell to be able to read it. Lisp may have spoiled me.

Re: Lisp has too many parentheses...

#66
post #19

Earlier quoted context omitted.

My guess is that what people complain about isn't really the parentheses, but rather heavy nesting of Lisp programs compared to other languages. If parentheses were replaced with something else, they'd probably complain about that something else.

Except that most modern lisps don't even nest that deeply anymore. At least, not anymore than every functional language that uses nesting to offer new immutable lexical scopes does. Seriously, the average nesting depth of a C program is maybe 3-4 (function, conditional, loop, etc), and C programs are simple . More complex languages like Java and C++ will easily have 4-7 levels of nesting on average. Clojure and Arc c…

What happens when a VP of Engineering decides that Cyclomatic complexity will be capped at 10:

http://stackoverflow.com/questions/105852/conditional-loggin...

Re: Lisp has too many parentheses...

#67
post #38

I've posted this here before, I'll post it again: http://img264.imageshack.us/img264/1397/lispnd7.png In practice, I don't find it has many more parens or angle-brackets than, say, C++ or Java. Considering (), {}, and in those two languages, I'd bet Lisp wins.

Languages with juxtaposed argument application (Haskell, OCaml) and meaningful indentation (Python, Haskell) will win over Lisp. Mixfix-based languages like Agda2 or Maude will win even more.

BTW, while Halstead metric predict various things about imperative languages like Algol/PL/1/C/C++/Java quite well, it fails when applied to Haskell: http://www.cs.stir.ac.uk/~kjt/techreps/pdf/TR141.pdf

And fail spectacularly - they have to introduce special "invisible apply" operator to make Haskell to be closer to imperative languages, just to do not look like they are cheating.

This is attributed to juxtaposition as application (as it reduces number of lexems) and to definition of functions by pattern matching. I think other languages with those two features would have same effect over predictive force of Halstead metric.

Re: Lisp has too many parentheses...

#68
post #39

Earlier quoted context omitted.

For things like cadadr, I just chop off the "c" and "r", and use the middle part to figure out the sequence of car and cdr calls. (cADADr x) = (cAr (cDr (cAr (cDr x)))), which would be (first (rest (first (rest x)))) in Clojure.

I suppose CL/Scheme programmers just learn by heart what those combinations do (ie. what kind of structure they work with), because to me both cadadr and the (first (rest ...)) sequence are equally meaningless at first glance. It's not easy to see what the data structure looks like. In Clojure it's usually more idiomatic to use destructuring, which I think is much more understandable since the form follows the struct…

or the "->" ("threading") macro, a recursive solution, or a lib like

http://groups.google.com/group/clojure/browse_frm/thread/11a...

Re: Lisp has too many parentheses...

#69
post #47
post #43

Money quote for the non-lisper: > For simplicity, let’s use the notation Yes, let's! Except in lisp, you can't. ;) (Yes, feeling snarky.)

Except you can, just use reader macros.

With these reader macros, can the code in the blog example be rewritten as below, so it still directly maps to the Lisp tree-like semantics, but be more readable?

  defun diff(expr, x){
    if(expr == x) 1
    else if(car(expr) == 'plus') ['plus', diff(cadr(expr), x), caddr(expr), x]
    else if(car(expr) == 'times')[
      'plus',
      ['times', cadr(expr), diff(caddr(expr), x)],
      ['times', diff(cadr(expr), x), caddr(expr)]
    ]else 0
  }

Re: Lisp has too many parentheses...

#70

Earlier quoted context omitted.

Paul Graham says: > We can get rid of (or make optional) a lot of parentheses by making indentation significant. That's how programmers read code anyway: when indentation says one thing and delimiters say another, we go by the indentation. Treating indentation as significant would eliminate this common source of bugs as well as making programs shorter. http://www.paulgraham.com/popular.html

By requiring parenthesis, indentation becomes so much simpler, the programmer doesn't even have to do it. It's done automagically.

It's done automagically for me in Python and Haskell, too. Instead of hitting the paren keys in Emacs, I just hit tab to cycle through the possibilities.

Because the Lisps have such a canonical way to indent them, in practise it feels very similar to significant whitespace with a funny input method.

Post reply on HN