4 ms·
> Java is particularly unforgiving for code where ones thoughts are unclear. Why is Java bad that way? Overly complex classes? In my experience, C++ is particu
by nyanpasu64 5y ago
> Java is particularly unforgiving for code where ones thoughts are unclear.
Why is Java bad that way? Overly complex classes? In my experience, C++ is particularly awful, since careless programming can lead to memory corruption, use-after-free, and nonlocal malfunctions and crashes.
- VHRanger 5y agoAt 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.
- nicoburns 5y agoI think classes in general. They are often a poor abstraction, and that leads to hard to refactor code.
- gorgoiler 5y agoJava involves lots of ceremony, lots of types, and a formal structure that lent itself to being a very verbose language. That has never sat well with any kind of source control where you are expressing your ideas with line oriented patches.
- bullen 5y agoI think you are confusing Java and the tools built on top of Java. I only code with JavaSE and only use 2 external dependencies (original json and dns4j, both minimalist and written by one man each), that said Java probably has the leanest API that has ever existed and potentially that will ever exist.