3 ms·
So, I've been working with Clojure professionally and this is simply not the case. Vast majority of the code is pure with side effects and state being pushed to
by yogthos 8y ago
So, I've been working with Clojure professionally and this is simply not the case. Vast majority of the code is pure with side effects and state being pushed to the edges as a thin imperative shell around the functional core.
There's a great presentation discussing Pedestal HTTP library for Clojure, and one of the slides notes that Pedestal has around 18,000 lines of code, and 96% of it is pure functions. All the IO and side effects are encapsulated in the remaining 4% of the code: https://www.youtube.com/watch?v=0if71HOyVjY https://www.youtube.com/watch?v=0if71HOyVjY
This is a completely typical situation when you're working with a functional language.
- foolfoolz 8y agothis is typical is any paradigm. even something like active record its possible to isolate all the actual DB interaction to just one file.
- yogthos 8y agoIt's not just about isolating DB interactions. Any code that deals with IO or creates side effects lives at the edges of the application. Vast majority of the code is written pure functions that can be reasoned about independently of the rest of the application. This is not practical in languages that rely on mutable data because things get passed around by reference. As soon as you pass a reference to an object to a function that's used elsewhere you end up with implicit coupling that's difficult to reason about. Of course, you could use immutable data structure libraries in imperative languages, but then it's completely on you to ensure that you never put any mutable data, such as an object reference, in those. At that point you might as well use a functional language.