3 ms·
There's one point where I'd argue with this - little classes that encapsulate a single simple domain concept are extremely valuable; an example would be a Path
by tragomaskhalos 6y ago
There's one point where I'd argue with this - little classes that encapsulate a single simple domain concept are extremely valuable; an example would be a Path type that facilitates building paths, canonicalizing them etc. The key is that they do not add to the cognitive burden, because their behaviour is (should be) obvious from the name and the name of the methods alone. Furthermore, by adding more nuanced type information, they improve the expressiveness and robustness of the code (as opposed to just using a String for everything).
One of my biggest beefs with Java is that, by virtue of the one-class-per-file concept (pace inner classes), the class is elevated to the level of a big deal in the novice programmer's mind, so that a little class with a very clear and narrow scope seems to be unworthy of existence, and we get the String-for-everything syndrome. Anecdotally, I have encountered exactly this attitude on projects.
- elric 6y ago> a big deal in the novice programmer's mind That's an interesting take, and I think you're right. In retrospect I have wondered why my more junior coworkers so rarely create new packages or new classes. Perhaps this is the reason. Will have to take that into account when doing reviews.
- pgwhalen 6y agoI'm optimistic that Records will help at least a bit with this problem over time. Simple data aggregates will come with much less ceremony than before. I've always been against generic Pair classes, and with Records there will be such an easy and superior alternative. https://openjdk.java.net/jeps/359 https://openjdk.java.net/jeps/359