3 ms·
First, if you're writing code in an editor, there's no problem with using that editor help you write the code. Complaining about having to use an editor to use
by lmkg 16y ago
First, if you're writing code in an editor, there's no problem with using that editor help you write the code. Complaining about having to use an editor to use paren-matching is like complaining about screws because they don't work so great without a screwdriver. You have tools, you can use them, you don't get man-points for scratching your code into a stone slab with a chisel.
That rant aside...
Trailing parens (and trailing braces in brace-y languages) do increase local readability, but they do so at a global readibility cost. They eat lines of code, which makes it difficult to see an entire code fragment at a time. Like all trade-offs, there are reasons why you should and shouldn't, and situations where you should and shouldn't. And the important thing is, the cost of trailing parens is higher in a Lisp than it is in your average brace-delimited language. This doesn't mean that it's always the right decision in C or the wrong one in Lisp, but on average C is more likely to get a net benefit than Lisp.
Lisp simply nests more than C-style languages. This means that you pay the line-costs more often and your code density goes down a lot faster. There are a couple of reasons that Lisp nests deeper, some of them from the language itself, some cultural. From the language side, C only uses braces for control structures, and those don't return values. In Lisp, both functions and control structures use parentheses, and control structures return values so they often get used as arguments to functions, increasing the nest depth. From the cultural side, C-ish languages use variable assignment and sequencing of operations as its fundamental operations and braced control structures are less frequent, while Lisp passes values as arguments to functions as its fundamental operation. Lisp tends to use additional parentheses in places where a brace language would use a semicolon instead of a brace.[1]
I have to say, the trailing-parens didn't really help me read the example that much. Having extra parentheses didn't help me figure out what line indented with what. In fact, it made it harder because there were more lines in the way. I suppose people who favor brace-y languages count braces rather than matching indentation, but like I said before, Lisp nests more so that's a lot of counting. Again, this doesn't mean that stacking parens is always right in Lisp, or even that it's right in this code sample, since I'm not the one writing or reading it. It means that, once again, these religious wars are silly and you should pick what works best, and my $/50 is that trailing is more expensive in Lisp so it doesn't increase readability as often. FWIW, people who claim Lisp code is naturally more dense could argue that Lisp can more easily pay those extra lines.
[1] Example idiomatic C-ish language (JavaScript perhaps):
a = foo(x, y);
b = bar(x, y);
return qux(a, b);
vs idiomatic equivalent lisp, which prefers to nest deeper rather than assign intermediate values:
(qux
(foo x y)
(bar x y))
- d0m 16y agoAbout your editor rant, I am not sure I agree with you. A great editor will help you for sure in productivity. However, a language shouldn't be unreadable without a correct editor. Imagine that, to read English, you actually needed a powerful editor.. Yes, some tools help you to be more productive (such as searching, replacing, etc.). So, again in my opinion, a good test to see if a language is readable is to print it and read it without any special tools such as syntax highlighting. If you can actually do that, imagine how syntax highlighting will make you even more productive! By the way, it may sound absurd, but try reading English or Python without colors..
- noahlt 16y agoI think it's interesting that in the language features vs editor features debate, Lispers tend to be on the "language features" side, while Java programmers usually favor powerful IDEs/editors. In this particular discussion, the sides are oddly flipped!
- eru 16y agoThe editor helps you write Lisp, by keeping count of parens, but once it's written, it should be readable without any special support. And reading Python without colours isn't much fun. Haskell can get away without colours in Papers, but the authors tend to substitute lots of mathematical symbols there with the help of TeX. (And they use other typographical hints instead of colour.)
- phaylon 16y agoI've always been wondering if people who can't stand using parenthesis highlighting are also opposed to using an IDE when writing Java.