News for hackers. Stuff that matters.
Re:Try Clojure by julianeon on Wednesday May 22, 2024 @02:54PM (#40444724)
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

Re:Try Clojure by ReleaseCandidat on Wednesday May 22, 2024 @03:14PM (#40444988)
> (* (/ (+ 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?

Re:Try Clojure by floodle on Wednesday May 22, 2024 @03:25PM (#40445147)
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?

Re:Try Clojure by barrell on Wednesday May 22, 2024 @04:47PM (#40446311)
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
Re:Try Clojure by ARandomerDude on Wednesday May 22, 2024 @03:36PM (#40445326)
Yes, especially because the language is so consistent.

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

Re:Try Clojure by julianeon on Wednesday May 22, 2024 @03:32PM (#40445269)
I would say yes, as someone who got used to it a few years ago.
Re:Try Clojure by eviks on Wednesday May 22, 2024 @03:33PM (#40445277)
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"
Re:Try Clojure by skydhash on Wednesday May 22, 2024 @03:55PM (#40445572)
The parenthesis highlight in any decent editor. So it always very obvious which operators apply to the operands.
Re:Try Clojure by eviks on Thursday May 23, 2024 @01:56AM (#40450965)
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

Re:Try Clojure by skydhash on Thursday May 23, 2024 @12:46PM (#40456956)
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.
Re:Try Clojure by eviks on Friday May 24, 2024 @06:08AM (#40464608)
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
Re:Try Clojure by ARandomerDude on Wednesday May 22, 2024 @03:33PM (#40445280)
Use the thread macro to make this easier to think about:

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