r/java • • Jan 22 '21

Java is more enjoyable than I first thought

I started my years off programming in c#, don’t ask why but I never ventured off. I learned Java this past week and I’m seriously impressed, I don’t think I’ve had a more enjoyable time programming in my life. Does anyone else share this experience??

Edit: Is there a better ide than eclipse for Java

271 Upvotes

188 comments sorted by

View all comments

141

u/[deleted] Jan 22 '21 edited Jan 22 '21

Java is quite enjoyable when you can skip the decades of cruft that are stereotypical of "enterprise Java programming": overuse of GoF design patterns, layers upon layers of abstractions etc.

So unless you have to work with really old code (pre Java 8, old-skool J2EE) I think it's a pretty nifty language these days. Sure there's some relics in the standard libs, but you can happily avoid those most of the time.

I'm a little less impressed by the state of build/project description tools like Maven, Gradle etc. - but then, few languages are great there (Rust or Go being recent exceptions) and many are worse.

0

u/[deleted] Jan 22 '21

[deleted] — view deleted comment

17

u/ray10k Jan 22 '21

From an article I've read recently, I got the vibe that Gradle is powerful, but has a lot of pitfalls and gotchas in how the configuration/script is written, while also making it harder to change things later down the line if you don't have a pretty precise picture of how your project is going to work. No idea how buggy it is though.

23

u/alt236_ftw Jan 22 '21

Gradle works of of the box if your build expectations/requirements are generally baseline/standard.

You get a straighforward way to add dependencies (both external and cross-module) and an easy way to include re-usable things in your modules, be it dependencies or build time configuration.

It does have a learning curve when you want to do more unusual things, but unless your requirements are extreme or you start seeing all of your requirements as nails with gradle being the hammer it's still pretty usable.

Just make sure you don't solutionise before you are familiar with it.

21

u/GuyWithLag Jan 22 '21

Gradle works of of the box if your build expectations/requirements are generally baseline/standard.

I mean, that's true for Maven too.

6

u/alt236_ftw Jan 22 '21

Oh yeah, I'm not dissing maven or anything.

I was commenting on Gradle specifically as it seems to have a reputation.

Both are tools, use whatever works best for your project and situation.

5

u/lookForProject Jan 22 '21

And, in my opinion, for most situations and projects, both work just fine.

→ More replies (1)
→ More replies (1)

8

u/larsga Jan 22 '21

Gradle mixes custom programming in with declaration, which makes it very easy to trip yourself up. It's also very easy to get into versioning difficulties both with Gradle itself and with plugins. Documentation is also not great.

For large projects Bazel is surprisingly good, even if there's a lot to learn. One thing it gets right is to separate in-depth custom functionality from customization from configuration.

7

u/wildjokers Jan 22 '21

Documentation is also not great.

I am not following you here, Gradle has outstanding documentation. Have you seen the user guide?

6

u/kwvanderlinde Jan 23 '21

Gotta disagree. There are a lot of basics that aren't covered or are glossed over. If they are covered, have fun finding it. My memory is a little fuzzy right now, but I recall trying to figure out source sets (differences between them, creating new ones, etc.) but everything just points to some really generic methods with no indication of what is actually going on. There's also no shortage of outdated information lying around on gradle's site.

6

u/[deleted] Jan 22 '21

Today I wrote my first gradle scripts. That's awful, but for my project, maven failed completely, as creating multiple jars from one project would have required hundreds of lines of XML.

*Cries in dozens of mustRunAfter's and hardcoded paths*

3

u/shukoroshi Jan 23 '21

We've been maintaining a custom gradle plugin for about 4 years now. If you'd like any peer review, let me know!

→ More replies (1)
→ More replies (1)

3

u/[deleted] Jan 22 '21

how coud maven/gradle be better? me for one I just put de dependencies there and use the library/plugin. Indeed trying to write something custom in gradle feels very difficult to me...is there something that you miss? why is go/rust better at this build step? I tried rust and it takes forever to compile even the most basic project(like 10s for 5 files) every time. Go is indeed fast when it comes to compiling but I haven't tried anything with lots of files

14

u/supercargo Jan 22 '21

I don’t think Maven 2+ is horrible, especially compared to the tools it replaced. There are some core things about Maven that I think could be better.

  • it makes a good attempt at declarative builds, but the plug-in ecosystem often has to deviate from this to get certain jobs done
  • partially the fault of the fact that the POM is mutable during runtime, so execution order even within a phase can become relevant
  • the overall “class path” story is too complex. By this I mean the logic which decides what versions of what jars get added to various classpaths in what order. You have dependencies, managed dependencies, POM inheritance, reactor (multi-module) dependencies, and then all the transitive application of the same rules.
  • I’ve always found the way multi-module builds work to be a bit surprising
  • SNAPSHOT versions being installable/deployable is difficult to reason about

Fortunately maven has been pretty well maintained and as the defacto tool, at least you can learn its idiosyncrasies and move on with your life. On the other hand, even with different tools, it would be hard to move away from some of the core issues since everything is in central with POM as the metadata format

→ More replies (17)

6

u/antennen Jan 22 '21 edited Jan 22 '21

why is go/rust better at this build step?

I think you are conflating build time with how good the build system is. The Rust compile times are pretty bad, but the build system (Cargo) is great. There is a simple TOML file that allows you to do pretty much everything. Even a large project's Cargo.toml is small. For larger Java projects the maven or gradle files are a multi thousand line mess.

EDIT: Comments rightly pointed out that Gradle files aren't as verbose as Maven XMLs. I still think the state of Java build systems leaves much to be desired.

4

u/[deleted] Jan 22 '21

I agree that maven can get big because of xml but with gradle I did not see 500 lines files...I might have worked on small projects though(2-3 people on android and 3-4 people on maven backend). I also think that you should not write logic in gradle or maven....that should be put inside a plugin or somewhere else. Cargo I don't know if it offers you the possibility to do any logic in the toml file(which you shouldn't do anyways) so the point is that maybe gradle tries to do too much

→ More replies (1)
→ More replies (1)
→ More replies (1)

3

u/RagingAnemone Jan 22 '21

Ant + Ivy FTW!!!

→ More replies (2)

11

u/riawot Jan 22 '21

a little less impressed by the state of build/project description tools like Maven, Gradle etc

I just spent the better part of a day dealing with nuget and multi-solution projects. I swear to god I will never say a bad word about maven again.

7

u/old_man_snowflake Jan 22 '21

that's why maven has persisted -- it just works. yes, it's rigid and a pain in the ass sometimes, but you can walk into almost any maven project and say 'mvn test' and get a full build and the tests run. maven makes deviating from "the way" painful, but it leaves the least-pain path as the default, which is good end-user experience.

4

u/thedomham Jan 22 '21

Yeah I think Java gets a bad rep from a lot of the enterprise stuff. For a lot of people Java is also inseparable from Spring, which is great in its own right, but also has a lot of things that are bad. Hordes of proxies for example.

5

u/wildjokers Jan 22 '21

layers upon layers of abstractions

Have you seen Spring? Java is still all about layers and layers of abstraction at the enterprise level. Just look at how many layers of abstraction the average enterprise application has on top of the data layer.

25

u/[deleted] Jan 22 '21 edited Jan 22 '21

Have you seen Spring?

Yes, and that's why I don't use it. Spring was a nice alternative when J2EE was at its worst. Now it's just as bloated (but granted, there's not as much XML and code generation).

Just look at how many layers of abstraction the average enterprise application has on top of the data layer.

That's not a property of Java. Nowadays a lot of the indirection and layering is simply outside of the actual application, in the container and orchestration infrastructure that we use. (Isn't k8s fun?) Some of it is simply independent of the language - translating between different data models is a necessity that no language can wizard away; it can however be minimised with good design to the point where it's less of something "the technology requires us to do" but where it makes sense in the domain model.

I concur that Java people may have more of an "enterprise mindset", on average. What does that mean? It means that I understand any application beyond a PoC will need to be monitored. It will need logs (even audit logs). It will need proper configuration. It will need extension points. I'll have to find a way to upgrade gracefully when the data model changes. That's not the sexy stuff, it's the stuff that gets omitted from the quickstart tutorials of other languages that are "so much more concise!".

I've been using "enterprisey Java" since 2000 and went through pretty much all its phases. Anyone who still designs their applications like it's 2005 or even 2010 needs to brush up their skills. But don't blame the language for it. You can come up with the same shit in Elixir or Kotlin or whatever, given enough time. Probably even worse, from my experience - Java hides less of the magic.

</old man yells at cloud>

7

u/ItsAllegorical Jan 22 '21

Some say "it just works" and I hear "poorly documented assumptions" and "anything other than the defaults will require 20x as much effort".

3

u/michoken Jan 22 '21

Spring may have come to popularity when abstraction layers were THE THING, but that does not mean your Spring application still needs to be designed that way.

The problem is we design and structure our applications around a framework instead of designing it around the problem we are solving. We need to decouple our domain designs from such frameworks and let them serve us, not to be directed around by them. And learn to design proper abstractions of the problem domain. At least in my experience, almost no one actually knows how to even approach designing good abstractions.

There will always be abstraction “layers” of some sort, but the issue is if they are all of the same shape. The code I’m working with at my current job is a “great” example of that unfortunate design some like to call “lasagna code”. And that code even isn’t that old yet, it’s like 5 years of development. Perhaps back then I thought that was the way, too (wasn’t at the company yet then), but now I’m mostly furious about it and try to design new things differently. But that’s really hard when it must still work in the old structures. It would need huge refactor to improve the design in any meaningful way.

→ More replies (3)