by zmmmmm · 8y ago · 0 comments
Is this really true? It's by far the most off-putting thing about Lisp dialects to me. Trying to get nested parentheses to match is extremely tedious when I have to do it in non-Lisp languages. It seems horrific if my whole programming experience is one long exercise in "why doesn't this bracket match!?!?!!". I know it can't be this bad because too many people have no problem with it, but it's the only thing I can think when I see some Lisp source code with 50 nested parentheses ...
When using Emacs, the editor can ensure the parenthesis always match. It can also show you which parenthesis match, and if you insist on allowing having non-matching parenthesis, it can show you exactly where they don't match. So even in that case you don't have to worry about it because the editor will point it out to you.
Parenthesis are probably the most trivial and unimportant thing about Lisp, and people get way too hung up about them.
What's far more important is the power that Lisp gives you, how easy it is to program what you want in it, and how elegant and easy to understand the solutions you come up with are.
Instead of having some kind of spaghetti code monstrosity full of ridiculous boilerplate as you would in other languages, you could have a nice and simple solution in Lisp. Isn't that worth allowing some extra parenthesis in to your code?
Yes. There comes a moment in which you suddenly stop minding parentheses. For me it was when I started reading SICP and doing its exercises on paper. After writing a couple Lisp expressions by hand, something clicked in my brain, and since then I don't need to count parentheses anymore.
I strongly suspect following the Lisp style of indentation and placing parens (closing parens go together, instead of one per line like in Algol-derived languages) is vital to achieving that.
After working with mostly Python and Clojure since 2015, I now have a similar gut reaction to curly brace languages that most people have to lisps. I find ClojureScript much more readable and aesthetically pleasing than Javascript.
Definitely - I have started writing JavaScript braces for nested callbacks in that style as well because it makes much more sense.
func Foo(s string) string {
println("hello")
}
And in Clojure: (defn foo [s]
(println s))
The Go code has two () pairs and one {} pair. The Clojure has two () pairs and one [] pair. There aren't more overall parenthesis, they are just in a different place. Any decent editor will catch missing parens just as they would missing braces in other languages.There are some cases where you do get a few more parens, e.g. with mathematical operators, but overall it's not that different, it's almost completely user perception.
I don't want to have to think about which delimiter I need where. Knowing that it's always going to be a parenthesis makes my life so much easier.
(let ((x 1)
(y 2))
(+ x y))
In Clojure, it becomes: (let [x 1
y 2]
(+ x y))Granted, it's a bit easier to pick them out with square brackets, but for my taste I'd rather just have homegenous delimiters everywhere.
How often do you want to do that? Wouldn't you be more interested in what the variable is called or who it's passed to?
(And code with 50 nested levels of parens is Bad Code, just like too much nesting in a C-like language)
The style in lisp is to keep all the closing paren on the same line: ))))
But in java or C you’ll sometimes see a function that ends like: } } } }
(Hmm my newlines didn’t cone thru on those braces)
Not exactly apples to apples comparison, but it illustrates how you can start to unsee those parens.
}
}
}
}
}
}
}
}