3 ms·
In clojure, there's the thrush operators: -> and ->> user=> (->> 10 (+ 2) (* 5)) 60 user=> (* 5 (+ 2 10)) 60 http://debasishg.blogspot.com/2010/04/thr
by mcav 16y ago
In clojure, there's the thrush operators: -> and ->>
user=> (->> 10 (+ 2) (* 5))
60
user=> (* 5 (+ 2 10))
60
http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html http://debasishg.blogspot.com/2010/04/thrush-in-clojure.html
- jacquesm 16y agoThat's exactly it! Neat, never knew that was in there. I really should do more reading before diving in to using something. Bad habit. It would be nice to see two fair sized chunks of code side by side, one in each style and then to ask a panel of programmers which is the more readable of the two. I'm beginning to slowly 'grok' functional code, I can read it a bit easier now than two months ago (exposure), but I still feel like with olives that it is an acquired taste. I hope I'll grow over that, it definitely doesn't feel natural yet, and it takes me much longer to understand a piece of functional code than it does when I look at 'imperative' code.
- mcav 16y agoI just started picking up Clojure (coming from Python) a couple weeks ago. It's hard to understand at first, but I'm really starting to like it more than Python. Once you get over the mind-backflip that comes with the leap from imperative to functional, it really feels a lot more coherent.
- jacquesm 16y agoThe biggest advantage I've noticed so far is that once it works it just keeps on working, it is almost like it is hard to create bugs in functional code than it is in imperative code. This must have something to do with the lack of side effects. For some fun I coded up a small site in PHP in a functional style (I can see a lot of HN'ers gouge out their eyeballs at this sentence, apologies, it was just an experiment), and it gave me a lot more practice in reading functional code. But the side effect free trick had - pun intended - a side effect by itself, the code worked the first time out after writing it, and that's unusual for a 1500 lines or so project, once the minor syntactical problems were dealt with (mostly quoting issues). That really was unexpected, if there is any concrete explanation for that (other than blind luck) I'd like to hear it, and if this is more common in the 'functional world'.