Solution design in Java/OOP vs. Clojure/FP - I/O anywhere or at the boundaries?


As a Clojure developer thrown into an “enterprise” Java/Spring/Groovy application, I have a unique opportunity to experience and think about the differences between functional (FP) and object-oriented programming (OOP) and approach to design. Today I want to compare how the solution would differ for a small subsystem responsible for checking for and progressing the process of fixing data discrepancies. The main question we will explore will be where do we deal with external effects, i.e. I/O.

Read more…

PS: I would be happy to hear feedback and better ways to approach the functional core - imperative shell data exchange. Thanks to @slipset for input!



Nice post. I think you’re touching on something important.

There’s so much talk about functional programming at the bottom. Where everything is pure, and you can expose what you need as a library. And with Clojure, it really is possible to formulate almost anything as a library.

But that doesn’t mean that all the hard stuff is at the bottom. How do you assemble your application? How do you connect the resources?

Reposting a direct reference of yours along with another from the same conference:


PS. What bugs me, though, is prioritization. How far should you go? One of the things I really like about Clojure is being able to put that impure thing into the start of a pipeline like (->> (slurp "file.txt") ... ). Clojure is a decent imperative programming language, when you need it to be. But I guess I’ve gotten more sensitive to what should be function arguments. And If I’ve got something “on the edge” which fetches some resource, that should probably be its own function, and not implicit somewhere else. Would love to hear other thoughts on this.


Hei Teodor, thank you! I am looking forward to the duct talk, I was aware of duct but it will be good to get to know it better.

You are right that there is far less about the “enterprise”, messy side of Clojure development, though it is much better than years ago. It is getting better and there are some good resources already (including Erik’s talk).

How far should you go?

Easy - it depends :wink: In a script or simple tool I would happily put everything into a single ->>. But as soon as it gets bigger and I start feeling the need to test the logic, it time to split it. A core value of Clojure is pragmatism so keep to that :slight_smile: .