6 ms·
At this point the issues with Java are cultural, but they used to be evolutions of constraints of the rigid "everything must be a class" model. If nothing in
by VHRanger 5y ago
At this point the issues with Java are cultural, but they used to be evolutions of constraints of the rigid "everything must be a class" model.
If nothing in the architecture can just be a free-floating procedure, not even a pure function, the system architecture will evolve around this
- oh-4-fucks-sake 5y agoKotlin has been a godsend when it comes to breaking free of Java dogmatic thinking. The effort to write good functional code is so much less. That's not to say that classes are useless. I try to limit class usage to data structures that do no more than: - Store data - Simple convenience functions that tell me about its state - Side-effect-free mutations (or data massaging) that have no external dependencies other than function params - Simple validation, if there are no external dependencies Everything else goes in a service/function.
- VHRanger 5y agoClasses manage something stateful. One anti-pattern/code smell I often see is finding classes in a service which should just be a functionally pure pipeline (eg. no internal state is managed)
- oh-4-fucks-sake 5y agoAgreed. Exception here is when you're making the trade-offs to buy into a DI framework--which you could argue is a descendent need from the "everything is a class" worldview. Pure/dependency-free util functions can very naturally live outside of all of this. But, the minute you have functions that depend on inherently stateful infrastructure (e.g. datasource connections--so, most applications), then those functions become inherently stateful--which makes them less natural to exist as pure utils and starts to make DI more attractive--which leads us back to placing pipeline code within classes. Alternatively, you could expose only the stateful pipeline code within singletons, but at some point you start to fight the community patterns--which means you start to lose out on community goodies. To be clear, this is all only based my experiences and I'm not dogmatic at all about any of this. Times change/everything-old-is-new-again. I'm sure classes will make a comeback, and then go out of favor again--as is life.
- ivanche 5y agoConverse is also true - if everything in the architecture can be a free-floating procedure, the system architecture will evolve around this.