47 points•ibobev•about 2 months ago•83 comments•

83 comments

whartungabout 2 months ago
The parentheses are large glyphs that distract the eye, and do not stand out (to the untrained eye) as delimiters.

Consider:

  (defun split-line (line)
    (remove-if #'(lambda (word) (string= word ""))
               (split-sequence:split-sequence #\Space line)))
Now imagine if we had some "lower weight" glyph besides the paren.

  .defun split-line .line,
    .remove-if #'.lambda .word, .string= word "",,
               .split-sequence:split-sequence #\Space line,,,
Obviously a contrived example replacing () with ., but you can see how "heavy" the parens and how they can dominate what the eye sees.

With experience, the parens vanish. The parens being large and common take control of the conversation more than they should.

Avshalomabout 2 months ago
this actually gets at the real problem. Lisps are wordy as hell. like jesus

  (split-sequence:split-sequence #\Space line)
now imagine if that was

  (split-string " " line)
image if the whole function was

  (defun split (line)
    (remove [\(word) (= "" word)] [split-string " " line]))
or even

  (defun split (line)
    (remove "" [split-string " " line]))

*using [] in place of rainbow parens for clarity of sub arguments
fweimerabout 2 months ago
I think with CLOS, you can go back to using single verbs for function names. However, this has a performance cost. Encoding the receiver type in the function names makes the call much easier to optimize.

What remains is field access. Curiously, first-edition K&R C actually required similar type-encoding in field names because field names were global:

https://usenet.trashworldnews.com/?thread=288637

Same for ML, which is roughly of the same age, except that it took much longer for ML-derived languages to lift this restriction.

On the other hand, every time I wrote down examples that I think should look really bad in prefix notation, like this one:

    p3.x := (p1.x + p2.x) / 2;
It is actually not so terrible with a sufficiently streamlined prefix syntax:

    (setf x p3 (/ (+ (. x p1) (. x p2)) 2))
But maybe there should be a mechanism that the reader transforms p1.x to (. x p1), in the same way that it transforms 's into (quote s). Then we get this:

    (setf x p3 (/ (+ p1.x p2.x 2)))
Or if there is a concept of a place:

    (set p3.x (/ (+ p1.x p2.x 2)))
But that probably needs static typing for an efficient implementation (or set needs to deconstruct its first argument during compilation).
Jtsummersabout 2 months ago

  (split-sequence:split-sequence #\Space line)
Why would you do that? You could just use `uiop:split-string` and import the function symbol into your current namespace so you can call it as `split-string`.

  (split-string "a b c")
whalesaladabout 2 months ago
I don't think the parens are the issue.

But when your function ends with ))))))))) -- that is the issue. Too much shit is being shoved into one method. But this is not the fault of lisp, it's the fault of the programmer who is wielding it.

kccqzyabout 2 months ago
That is frankly not a problem at all. People rarely bat an eye when your Python function ends by having eight simultaneous levels of dedent. People definitely don’t bat an eye when your HTML ends with </span></span></div></div></td></tr></table></section></body></html>. All you need is just good indentation, which is enforced in Python but optional in Lisps; then lazy programmers take shortcuts and don’t indent at all.
waffletowerabout 2 months ago
OMG, the "improved" example is so cluttered and far far far less readable -- and even foreign -- to someone like me that has developed using lisp professionally for at least 10 years.
regenschutzabout 2 months ago
That's a crazy effect. For me, as someone who has a very minimal understanding of Lisp (apart from messing with it in Emacs for at most an hour), the improved version is much more readable.
acomjeanabout 2 months ago
Lisp is why I started using emacs and its parens matching features.
pfdietzabout 2 months ago
Lisp isn't difficult to read, so I don't understand the question.

This feels like someone who doesn't know French asking "what makes French difficult to read?"

stcgabout 2 months ago
Exactly, it's just unfamiliar to most people.

I find Clojure (a Lisp) more readable than many other languages. It's the style I like for pseudocode. Because I used it a lot. It's familiar.

"Easy" is relative and doesn't mean anything without a subject. Easy for whom?

caaqilabout 2 months ago
> Lisp isn't difficult to read

You'd be surprised how seemingly simple things can be hard for some. As an example, it's extraordinarily difficult for some HN users to read beyond the title and try to understand the reasoning behind it, so they instead settle for showcasing their intellectual prowess by answering the question outright as if that was the thesis. It's a very smart strategy, I must say.

mpalmerabout 2 months ago
You should really follow the HN commenting guidelines, specifically #1, 7 and 11.
iLemmingabout 2 months ago
> read beyond the title

Feels good to find a perfect opportunity to be witty and snarky, yeah? Well, allow me to murder this vibe of yours. Titles do exist for a reason. This article's title specifically, assumes too much. It's nearly click-baity. Imagine a title like "Why does the Holocaust feel like a hoax?", and then it goes into intricate detail to prove it isn't. Some people still get triggered by the title alone.

whalesaladabout 2 months ago
Personally, I find that a lot of LISP hackers put way too much logic into a single form or method rather than breaking it into smaller components that can be composed together. And I think that's often why we see frustration with LISP is that you'll have something that is indented really deep when it could be a much smaller function that's leveraging other functions. It's even worse in certain lisps like Clojure, where you'll see a lot of shorthand symbolic stuff, like for anonymous functions, or when you're using core.async, where you look at it and you think, is this brainfuck?
so-cal-schemerabout 2 months ago
100%.

The better way is illustrated by this early example from SICP:

  (define (sqrt x)
    (define (good-enough? guess)
      (< (abs (- (square guess) x)) 0.001))
    (define (improve guess)
      (average guess (/ x guess)))
    (define (sqrt-iter guess)
      (if (good-enough? guess)
          guess
          (sqrt-iter (improve guess))))
    (sqrt-iter 1.0))
Observe that the problem of computing square roots breaks up naturally into a number of subproblems: how to tell whether a guess is good enough, how to improve a guess, and so on. Each of these tasks is accomplished by a separate procedure. The entire sqrt program can be viewed as a cluster of procedures (shown in Figure 1.2) that mirrors the decomposition of the problem into subproblems.

The importance of this decomposition strategy is not simply that one is dividing the program into parts. After all, we could take any large program and divide it into parts—the first ten lines, the next ten lines, the next ten lines, and so on. Rather, it is crucial that each procedure accomplishes an identifiable task that can be used as a module in defining other procedures.

etc.

1.1.8 Procedures as Black-Box Abstractions

https://sarabander.github.io/sicp/html/1_002e1.xhtml#g_t1_00...

joshlemerabout 2 months ago
And the reason that LISP code tends to be reluctant to split things out into multiple forms with variable assignment IMO is because it introduces a new level of nesting. It's too much friction to go from

    (defn foo [] 
       (+ 1 2))
to

    (defn foo []
      (let [x 2]
         (+ 1 x)))
I wish that there were some kind of macro available in Clojure that would provide a local "def" kind of functionality that doesn't pollute the namespace and just creates a binding in the parent scope. So that you could do something like:

    (defn foo []
       (let! x 2) 
       (+ 1 x))
perrygeoabout 2 months ago
> I have not yet encountered a fully satisfying explanation as to why Lisp is perceived as being less readable.

Difficulty is, by definition, relative to one's skill. You cannot so quickly discount the fact that 99% of programming is taught in Java/C style language syntax. If you've had lifelong exposure to Lisp, you might feel exactly the opposite. The author does a poor job of justifying why these pop-cognitive-psych theories should have more weight than prior exposure.

Personally, as someone with decades of exposure to both styles, I look at the factorial example and see everything I love about Lisp syntax - consistent, no magic keywords and syntax to memorize, it represents a tree just like my mental model of code, there's no way to fall through and forget an else, expressions instead of statements, no early returns ... literally everything about the Lisp example is more readable to me. YMMV.

Supermanchoabout 2 months ago
> Difficulty is, by definition, relative to one's skill

It's a factor and not the sole factor. Saying it's "by definition" is incorrect.

> The author does a poor job of justifying why these pop-cognitive-psych theories should have more weight than prior exposure.

There's no reason to believe either way, except one path has decades of evidence. Human behavior is not overcome by programmatic "elegance". The dismissive "pop" prefix is signaling bias.

> no magic keywords and syntax to memorize

ie no syntactic sugar. Pointless repetition is counter productive.

>a there's no [logical] way to fall through >b [no way to] forget an else, >c expressions instead of statements >d no early returns

b. The interpreter catches it. d. Pointless execution is counter productive.

> literally everything about the Lisp example is more readable to me

That's a single data point. Statistically it's worse, but you're practiced and apparently still physically able to quickly discern the nested count (or use an IDE). Yet another example of a position that is counter to existing studies. Heavy nesting is error prone, even when a program compiles (eg Monden et al., “Evaluating the Applicability of Reliability Prediction Models between Different Software,” ISSRE 2001)

perrygeoabout 2 months ago
Of course it's a single data point, stating my personal preference and the objective characteristics of the code that make it more readable, to me. That's what the article did too! But they tried to use their biases to establish a claim on objective truth. That's the difference - I'm not trying to make a generalizable scientific claim!

I'm trying to say that making such claims in the first place is invalid.

There is no language that is objectively more or less readable. Yes, I've read the studies. No, none of them come close to adequately addressing the confounding factor of prior exposure/education. A randomized controlled trial starting from childhood could establish such truths, but such an experiment has not been done. Until then, small-n studies that don't address this flaw in any way yet continue to make broad claims - "pop" science is perhaps not dismissive enough.

convolvatronabout 2 months ago
every time I get to use lisp syntax I feel a sense of relaxation, as if the background stress of thinking about precedence and the meaning of all these magic sigils and control flow constructs just melts away and I can finally see clearly what's going on. my first professional programming language was lisp, and almost every single project in the 35 years afterwards was C style. but it still feels like home.
tombertabout 2 months ago
I'll repeat what other people here have been saying: I don't think Lisp is actually "hard" to read, in any objective sense.

It's "difficult" to read because it's different that other languages, but I think some of those differences actually improve readability once you understand the language. The forced use of parentheses everywhere guarantees that precedence is never ambiguous, for example.

so-cal-schemerabout 2 months ago
I wouldn't say "never ambiguous" (at least for Scheme):

140 Assignment introduces a subtlety into step 1 of the evaluation rule. As shown in Exercise 3.8, the presence of assignment allows us to write expressions that will produce different values depending on the order in which the subexpressions in a combination are evaluated. Thus, to be precise, we should specify an evaluation order in step 1 (e.g., left to right or right to left). However, this order should always be considered to be an implementation detail, and one should never write programs that depend on some particular order. For instance, a sophisticated compiler might optimize a program by varying the order in which subexpressions are evaluated.

https://sarabander.github.io/sicp/html/3_002e2.xhtml#FOOT140

Read the full thread on Hacker News →

Related stories