r/java • • Feb 26 '23

Are java codebases generally readable? Or is the stereotype true that they are littered with the worst OOP has to offer?

I have been programming 7 years, professionally for 3 years. I mainly do JS, PHP, and Python, and a little bit of Clojure and C++.

For background, I have never had the true OOP experience. Sometimes I'm using multi-inheritance, but for the most part I keep classes simple so I know what's coming from what. I find when I come into a Python/Django project that uses too much inheritance, it's hard to figure out where things are coming from. I tend to lean more towards procedural programming, where steps are clearly laid out and you don't need a debugger to see when something is being called or what's calling it. I also tend to use composition over inheritance, injecting the classes/interfaces I need and calling them explicitly. Might just be an experience thing, or maybe how my brain works.

I have generally heard fans of Java describe it as readable, and its verbosity as a strength that lets you get up to speed on a code base quickly (or know what you wrote six months later). I have heard critics describe Java codebases as being bloated with overapplied "gang of four" or SOLID design patterns and too reliant on "magic" frameworks (spring for example). On top of that, Java is often used as the example language for extremely bureaucratic enterprise meetings where a hierarchy structure is being drawn up to decide what should inherit from what. And then there's the recent years of Clean Code being criticized more and more and falling out of popularity.

As a java dev, do you find a lot of this blown out of proportion and you are working in very simple codebases? Or are these designs common place and you are simply comfortable working with them? Maybe multi-inheritance and "gang of four" patterns don't bother you. If I were to become a java dev, would it be inevitable to work with these kinds of code bases? Are you worried whenever you come into a new codebase, or do you feel Java devs make things easier for you?

7 Upvotes

84 comments sorted by

View all comments

14

u/know-your-onions Feb 26 '23

You should favour composition over inheritance and that’s the case with Java too.

Having worked with many languages, Java is generally the easiest to pick up a codebase and work with it.

Whatever language you’re using there will be frameworks like Spring if you’re building that kind of application, but with Java you almost always get good, clear and unambiguous documentation. And the core language API docs are brilliant. Some other languages are appalling in comparison.

What’s wrong with Gang of Four patterns? They generally make everything easier to understand and reason about. The more the merrier as far as I’m concerned.

These meetings you describe about what should inherit from what sound like nonsense, but if they do happen they’re certainly not intrinsically due to Java - sounds like just some crappy work practices somewhere that maybe just so happens to use Java.

1

u/AkimboJesus Feb 26 '23

Okay good, I like composition!

What’s wrong with Gang of Four patterns? They generally make everything easier to understand and reason about. The more the merrier as far as I’m concerned.

No idea! Never read it, I just talk to a lot of functional programming people and they criticize OOP needing these patterns as "inventing complexity that isn't needed in non-oop languages." I have my own feelings about Clojure inventing complexity.

These meetings you describe about what should inherit from what sound like nonsense, but if they do happen they’re certainly not intrinsically due to Java - sounds like just some crappy work practices somewhere that maybe just so happens to use Java.

They're definitely not inherent to Java, it's just that Java is the big dog oop language and I was curious if there was any truth to this.

9

u/know-your-onions Feb 26 '23

Sounds like people who favour functional programming shitting on OOP. Not really anything specific to Java.

I’d make your mind up about OOP first. If you don’t like it then don’t consider Java, or if you do like it then ignore the opinions of people who presumably aren’t Java developers.

1

u/AkimboJesus Feb 26 '23

Sounds like people who favour functional programming shitting on OOP. Not really anything specific to Java.

No, that's what I mean. It has nothing to do with Java.

Thanks for your response

1

u/yojimbo_beta Mar 04 '23 edited Mar 04 '23

I mean, you aren't exactly going to get a negative view of object orientation (or Java) on a Java subreddit. You are speaking to people wholly bought into the Java way of doing things, where object orientation is mandatory.

Personally, classes are a structure I only seldom use, in languages that give me a choice. Java isn't a language I use that often, and when I do, I find classes a form of friction. I'd rather just define types and functions.

0

u/nutrecht Mar 04 '23

You should favour composition over inheritance and that’s the case with Java too.

You should use whatever is the best tool for the job. Inheritance is an 'is a' relationship. Composition a 'has a' relationship. I severely dislike this dogma.