You’d expect the longest and most costly phase in the life cycle of a software product to be the initial development of the system, when all those great features are first imagined and then created. In fact, the hardest part comes later, during the maintenance phase. That’s when programmers pay th
As an FP-fan interested in Clojure, how does one track if functions are pure in Clojure? I had assumed this was not possible, due to it not being statically typed (although I gather there is 3rd-party support for gradual typing).
There is nothing stopping you from making an impure function, but the language naturally guides you towards writing code that’s composed of a bunch of functions that transform data. Clojure also has explicit containers for mutable data and those have their own semantics, so you can’t accidentally cause mutation.
It’s also worth distinguishing between different kinds of side effects. One type of effects is doing things like logging, which in my experience are generally harmless. The type of side effects that I tend to worry about are the ones that couple functions together via mutable references.
And yeah, Typed Clojure library lets you do gradual typing, but it hasn’t really caught on with the community so far. Most people prefer using runtime contracts with Spec and Malli.
Thanks - I was just wondering how this somewhat precise statistic was obtained.
Otherwise, all that makes sense generally, though I tend to model logging as an effect in statically typed languages with effect systems. But I agree that it isn’t the most important thing!
I’m not sure how the statistic for Pedestal was obtained, don’t recall if the talk mentions it or not. There are static analysis tools for Clojure like clj-kondo that can provide these kinds of insights. You could see what parts of the code are pure based on what functions get called for example.
Sorry - I didn’t realize your original link was to the video and not the project. After watching it (good talk!), I found the clip in question. It seems like he is just saying that 96% of the codebase is functions (of any sort), not that 96% of the functions in the code are pure.
OK yeah, I misremembered the exact phrasing. You’re right he doesn’t say the functions are pure necessarily.