← Back to context

Comment by ecshafer

8 hours ago

Java is very fast. You just have to account for the amount of absolutely terrible written Java code full of 6 levels of inheritance, 6 levels of nested loops and AbstractFactoryFactoryFactoryProviderImpls out there to slow it down. I swear I have seen so much Java code that in the name of "abstraction" and "maintainability" they would take x + y and turn it into 8 classes and method calls.

Really the fundamental problem is that Java teaches the class as the fundamental unit of abstraction, rather than the function. (It goes so far as to not even have functions that exist independently of a class; even "static" functions must have a class to serve as their namespace.) It is class-oriented programming, not object-oriented programming. When you are really oriented towards objects, naturally you will want functions to be first-class objects. That way you can actually compose them in all the usual ways that objects are composed, instead of being limited to composing them at call time (by sequentially calling them).

When functions are first-class objects, so much of the GoF book just dissipates into the ether. You don't have a "Command pattern", you just have a function that you pass as an argument. You don't have a "Factory pattern", you just have a function that you call to create an instance of some other thing. (And you don't even think about whether your "factory" is "abstract".) And so on and so forth. There is value in naming what you're doing, but that kind of formalism is an architectural smell — a warning that what you're doing could be more obvious, to the point where you don't notice doing it for long enough to think of a name.

I think that school of Java is on the way out. Since it's absurdly backward compatible there's a lot of factoryfactory code still lingering, but I don't see it being written a lot.

Though there are a lot of unfortunate "truths" in Java programming that seems to encourage malignant abstraction growth, such as "abstractions are free", and "C2 will optimize that for you". It's technically kinda mostly true, but you write better code if you think polymorphism is terribly slow like the C++ guys tend to do.

Yeah, I have been disenfranchised by this style of programming. Its why I prefer languages like Python, when you use objects / classes as needed.

  • Modern Java, obviously is still objects everywhere, but the deep inheritance is really discouraged. Interfaces with default implementations, records, lambdas. There is just a lot that has moved the culture away from that style of programming, but not all places have moved.

    • It's a shame that this Java culture left its mark on the Python standard library (notably, in `unittest` and `logging`; the framework for text encodings is also highly boilerplate-y) and a fair bit of the ecosystem (pip has some classes like `class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller)` in its own code, to say nothing of what's vendored) already, though.

      1 reply →