5 ms·
As a Lisp/Clojure beginner, I don’t find s-expressions any harder to read – in fact, I like how much they take away the cognitive load associated with rememberi
by phforms 4y ago
As a Lisp/Clojure beginner, I don’t find s-expressions any harder to read – in fact, I like how much they take away the cognitive load associated with remembering and applying syntax rules in other languages.
But for me there is one exception that often hecks me up: comparative operators `<`, `>`, etc.
It might be due to the conditioning of infix notation in math education, but when I write `(< x y)` or `(> x y)` I somehow often manage to get the order confused, while this never happens with `x < y` or `x > y`.
I wonder if other Lisp programmers experience the same issue. This is my first year programming exclusively in Clojure, so maybe I just need more time to get used to it.
- moron4hire 4y agoIf'n you write your comparison operators as `(x . < . y)`, they're infix again! Kinda!
- thom 4y agoIf it helps, I always imagine a little guy skiing down the top of the sign, > he has to ski to the right, < he has to ski to the left. That's the direction the arguments are going highest to lowest.
- phforms 4y agoI think this might actually help, thanks! Maybe my problem was that when I write `(< a b)` I unconsciously read `< a`, which is where the confusion begins when I don’t explicitly think about the order. But the skiing guy helps to make it clear und easy to imagine what is going on (especially when I keep in mind that the operator is variadic in Clojure) and hopefully this will replace my “autocomplete error” in the long run.
- ctrlmeta 4y agoI don't have the same experience. I find s-expressions more pleasant to read. On the other hand, I find the syntax of C, Python, etc. to be jarring! The syntax of Rust and C++ feels like nails on chalkboard to me. What I find even more uncomfortable about C++ and Rust (and Python to some extent) is that they keep innovating on syntax and the syntax becomes more and more complex as years go by. Compared to that mess, Lisp's s-expression is a breath of fresh air. The brain ignores the parentheses soon (just as the brain ignores the braces in C-like languages) and relies on the indentation to understand the structure of the code. Having said that I do find the prefix notation slightly unintuitive for complex math formulas. Simple stuff like (< x y) is clear to me. No confusion there. But something like the formula for finding quadratic roots feels a bit unwieldy in s-expression syntax. I am sure that is because of years of conditioning of infix notation. Because pre-fix (or post-fix) are purer and unambiguous representations of the mathematical operations we perform. Yet conditioning has made pre-fix or post-fix hard to read for complex math formulas.
- taeric 4y agoI found that a lot easier to deal with if you embrace the added arity of the comparisons. Specifically, I don't read (< x y) as "x less than y", rather, I read it as "increasing x to y." This can work with (< x y z) to "increasing from x to y to z." (That make sense?)