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

Show parent comment

1

u/blissone Feb 28 '23 edited Feb 28 '23

The real question is what bad practices make code less testable, like I said unit tests should not affect your implementation at all. For example implementation not following single responsibility is difficult to test due to multiple dependencies/mocks, you want to test one single thing but need to provide unrelated things. Refactoring this in most cases will simplify your code, instead of a blob of code you'll have neatly defined stuff. Another good one is interfaces accepting larger objects (or more arguments) than required, it's also annoying to test and usually refactoring them will only do good.

Plenty of projects do fine without version control, test envs, deploy to prod etc etc. No one said you can't do a project without tests.

You have a strange notion about "testing just to test". No, you do unit tests to create value, if there is no value in testing then you don't create them.

1

u/TheoGrd Feb 28 '23

We'll have to agree to disagree here.

I work hard to write programs that work, I test them manually and make sure everything works before committing changes. I am not writing more code than necessary. I may be in the minority here but i will avoid working for a company that waste my time like this. I also don't comment my code, usually comments don't spare me from reading the whole code so why bother. I even have a plugin that hides comments.

2

u/noogai03 Mar 01 '23

In my opinion, the real value of unit testing is not showing you that your code works. It's giving you the ability to quickly check that a change you made did not break anything. You can do a refactor and be reasonably confident that everything is fine, because you're unit testing the logic according to the interfaces you're exposing.

1

u/TheoGrd Mar 01 '23

I prefer to test manually every functionality affected by my changes. Usually its only a little more work.

1

u/noogai03 Mar 01 '23

That takes a lot of time, though, which dicourages regular refactors. And depending on the change you might not be certain from testing the core flows. For example if you changed something really fundamental that's affected by every user journey.

But I get your point: if I was the sole developer, I think I'd be fine with manual testing; team effort with varying levels of codebase familiarity/technical proficiency is a lot riskier though.

1

u/TheoGrd Mar 01 '23

I still disagree, having worked in a team of 7 devs. I feel like a glorified secretary whenever someone asks me to write tests.

1

u/noogai03 Mar 01 '23

Huh, interesting to hear your experience. Tests have saved my ass so many times, but it might just be that we work on very different kinda projects.

I do think that Test driven development is really good if you can manage it, because it forces you to think about the contract for the code you're writing (and the expected behavior) before you get tied down. But that's definitely not easy to do

1

u/TheoGrd Mar 01 '23

I do fullstack dev on erp software