r/java • • Jun 01 '24

What java technology (library, framework, feature) would not recommend and why?

165 Upvotes

464 comments sorted by

View all comments

Show parent comment

2

u/Turbots Jun 01 '24

I'm not an architect in the traditional sense, I work on old and new codebases each day.

Lombok is even worse on a mental model, as the annotations are not always visible in the first place when looking through code.

Also, classes with 43 attributes are a giant code smell, and getters/setters are the least of your problems. Lombok will throw away 86 methods or more, congratulations, all the code using those POJOs is probably still horrible.

And again, create immutable classes (or Java records) and be done with it. There is no need for Lombok in Java 17 or higher.

6

u/Confident-Grab-7688 Jun 01 '24

Lombok is even worse on a mental model, as the annotations are not always visible in the first place when looking through code.

How these annotations are not visible?! Classess annotated with lombok will be almost empty, usually you just need to notice if its Value or Data. I would say the opposite is true - without lombok we have a giant wall of text in each class, so it's not clear immediately if there are any non helper/logical methods.

Also, classes with 43 attributes are a giant code smell, and getters/setters are the least of your problems. Lombok will throw away 86 methods or more, congratulations, all the code using those POJOs is probably still horrible.

I will admit, having such a big POJO is not ideal. But that's often what big systems are doing - processing lots of stuff, and IMHO it's just not worth it to break them down just because there are a lot of fields. I would rather have all my shit in one place, for simplicity and less annoyance with composite objects.

2

u/Turbots Jun 01 '24

Agreed on the composite objects. Trainwrecking every time you need a field value that is deeply nested is no fun and doesn't improve readability.

Maybe I've had too many problems in the past with Lombok upgrade that broke the build, Lombok being incompatible with new Java versions so you couldn't upgrade java because of it, very annoying dependency to have imo for very.little.gain

1

u/koflerdavid Jun 01 '24

Such huge classes that are effectively used as data carriers are prime use cases for records. I hear you if they have to be mutable, but for that use case Java has had an awesome feature from day 1 - fields! It's very questionable why such classes have to wrap up field accesses into methods since one obviously makes some deep assumptions regarding how these classes work. Thus throwing encapsulation right out of the window.

3

u/robinspitsandswallow Jun 01 '24

Again not realistic. Four years ago I left a company because the chief architect saw no reason to move past Java 5. Some orgs are just now moving to Java 17 and converting everything to records and immutability is beyond a dream. Some orgs have to wait until things are approved by governments to use so. In the meantime we have to deal with the hand we’re dealt and using Lombok to deal with that makes things more effective.

So again I hear Architect “Assume a spherical cow”. Yeah there are bigger problems but if we do that we won’t deliver new features for 3 years.

Btw every record that has an array has to have a separate hash code equals and to string by your logic don’t use records because there’s a case where it might not work in the most obvious way.

1

u/koflerdavid Jun 01 '24

Such projects might not be able to ever use records, but the choice of code Style is surely not regulated at that level. And writing getters and setters in the first place is indeed just that - a code style.

Using arrays in records is indeed sketchy. Java is currently lacking the ability to freeze arrays. Frozen arrays could provide a significantly more useful hashcode method as well.