Hacker News new | past | comments | ask | show | jobs | submit login

On the contrary - I think it's much easier!

The real advantage of this notation is that it's much, much easier to stack calculations.

Example:

(/ (+ 34 68 12 9 20) 140)

You can imagine how the first part of that could come about:

(+ 34 68 12 9 20)

And then the second part (pseudocode):

(/ sum 140)

In Clojure it's easy to mash them together, or for example to paste the first calculation in the second.

(/ (+ 34 68 12 9 20) 140)

Want to go further? Easy: add another enclosing parens.

(* (/ (+ 34 68 12 9 20) 140) 1.5 2)

Note how we're stacking in a more human-readable order - a new calculation starts on the left hand side, the first thing we see as we read it.

Compare how verbose the alternative is:

((34 + 68 + 12 + 9 + 20) / 140) * 1.5 * 2




I'd take the verbosity over having to count the operators from the start of the line to figure out which one are used at the end of the line "1.5 2"


The parenthesis highlight in any decent editor. So it always very obvious which operators apply to the operands.


This reduces the friction, but doesn't eliminate the needles back and forth. Breaking context locality is just bad

The threads example in another comment is way better


There’s no needle back and forth. Everything in parentheses is a complete expression, like a formula. You have the operator (function) and the operands (args). Think of it as add instead of + and multiply instead of *. You get used to it very quicly and then it does not matter.


It's not about thinking differently, it's about operator location, you simply don't know with long nested function what operation is performed at end-3 nest unless you look at beg+3


> (* (/ (+ 34 68 12 9 20) 140) 1.5 2)

The problem with that is by the time I reach `20)` I have already forgotten what operation I'm in. I'd write it more like this:

    (* 
      (/ (+ 34 68 12 9 20) 
         140) 
      1.5 2)
actually I'd write this as

    (/ 
       (* 2 (/ 3 2) (+ 34 68 12 9 20))
       140)
> ((34 + 68 + 12 + 9 + 20) / 140) * 1.5 * 2

Why not (34 + 68 + 12 + 9 + 20) * 1.5 * 2 / 140?


A programming language should be first and foremost precise and readable, not concise. I can barely understand the clojure version but when I read the "traditional" one I don't even need to think.

If you work with clojure a lot, does it become natural?


I've worked with clojure for years, and it becomes pretty normal, but I don't think it inherently get's better than the alternative, just on par... although it's realllly nice not to ever have to think about operator precedence, especially if you have to switch between languages.

Where it really shines though is when you use the threading macro and inline comments to make really complex math a breeze to review:

  (-> (+ 34 68 12 9 20) ;; sum all the numbers
      (/ 140)           ;; divide by a quotient for some reason
      (* 2)             ;; multiply by two for it's own reason


Yes, especially because the language is so consistent.

99% of the syntax is just (foo arg1 arg2).


I would say yes, as someone who got used to it a few years ago.


Use the thread macro to make this easier to think about:

(-> (+ 34 68 12 9 20) (/ 140))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: