I think this was a perfect demonstration of why classes are the "right" way to write code at scale - at least with our current languages and tools.
Early in my career I drank the OOP coolaid and got bitten hard over and over again. After years of abuse from trying to make all code into nouns and fighting mangled nests of inheritance, I rebelled and went full FP (So I just drank the other side's coolaid, sigh). I even purposely flunked an interview challenge once because I wanted to prove that FP was "better". Not my finest moment.
I've now come to accept that a lot of code has dependencies that you want to configure prior to calling a function. A class constructor is a very natural way to do this.
So now, I still try to write pure functions when it's reasonable but I don't shy away from creating an encapsulating class when a function has a dependency that is unnatural to pass in at call time (e.g. environment variables).
Unfortunately, most code does have those kind of dependencies so most my function are now methods on a class. Part of me still wants to create patterns and tools in FP that solve this at least as good as classes do but I think that's just due to my prejudice of OOP.
So, Jon, to reiterate, I think you perfectly demonstrated how classes are the preferred way to do DI, so we should be using them. I still avoid the term OOP though ;) Most code is more naturally thought of as verbs, not nouns. Is it even a thing to say I write functional classes?
Jonathan Barnett
DevOps and Full-stack engineer