r/java • • Apr 20 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
291 Upvotes

295 comments sorted by

View all comments

131

u/cville-z Apr 20 '21

Java is underhyped only if you weren't programming in 1995-2005, when it was criminally overhyped. I'd say it gets the right amount of hype now.

Also this article is written like someone just discovering object-oriented type-safe compiled languages for the first time after only ever programming in perl, ruby, or Javascript.

36

u/shponglespore Apr 20 '21 edited Apr 20 '21

I'd say just the opposite. Around that time I was working at a company where I successfully argued for using Java instead of C++ for a major project, and that led to the company becoming an all-Java shop because everyone agreed it was a huge improvement. These days Java has a lot more serious competition from languages like C#, Go, Rust, and even JavaScript. I don't touch Java code very often these days, but when I do it's usually painful because it seems like if you want to be taken seriously as a Java programmer these days, you have to rely on things like DI frameworks and magical annotations to such an degree that it becomes very hard to read the code in a project you're not intimately familiar with.

14

u/deadron Apr 20 '21

DI frameworks, when used properly, make testing substantially easier! If you don't like your DI framework then are probably not writing enough tests to really see the benefits. There are other use cases but in my experience this is when it really shines.

2

u/Serializedrequests Apr 21 '21

How often do you ever inject anything other than the one implementation of something that exists in the project? Honestly?

I maintain a huge spring boot REST API at my current job and 100% of DI in unit tests could easily be done some other way. A lot of the most useful stuff is overwriting private properties which seems pretty hinky to me.

1

u/deadron Apr 21 '21

Most of the time what I use it for is to inject mocks in place of classes performing IO such as database calls or external service calls. While you can get away with testing against a real database(dockerized or otherwise) if you are making calls to something like twillio, and you cant inject a mock replacement for the class making the calls, you effectively cant run tests using that code path.

The caveat here is assuming you are doing constructor injection(or UGH public setter injection) many of your tests can be written without even using the DI container at all. Of course something still has to be creating the classes at runtime and a DI container is the simple solution usually.

If you have to overwrite private properties to test thats a perfect example of something that should be added as a dependency to the class and injected instead.

1

u/Serializedrequests Apr 24 '21

Ah, my project has approximately 1 use of the AWS SDK, which I just turn off to run unit tests. The reason for private property injection is JPA repositories. So many of them are needed to do anything non-trivial it feels like that pure frustration of having to go inject yet another repo to check that data was changed correctly has forced us into this, specifically in unit tests.

1

u/deadron Apr 25 '21

Yeah. Jpa is a pita. I try to avoid it whenever possible. Usually I try to at least put jpa behind a service layer that can implement higher level operations and can be easier to test/mock for other tests. It's tricky with an existing codebase though.

→ More replies (10)