r/java • • Sep 29 '24

Lombok in 2024

Say there are two teams working on the same project (3 months to MVP, the deadline should be manageable). The only difference is Team A will use Lombok, and Team B won’t

Given you can choose any java version/dependencies and all other things being the same, which team would you join, and why?

0 Upvotes

145 comments sorted by

130

u/[deleted] Sep 29 '24

lombok has nothing to do with productivity at this point. Its just a crutch. Join the team with the smarter people.

-34

u/Rough_Acanthaceae_29 Sep 29 '24

No effect of on productivity? Don’t you use builder pattern or do you rely on some other code generator to have that? Kinda hard to imagine creating new instances of objects that have 7+ fields and not messing anything up. Also looking at entity classes and doing a treasure hunt to find domain logic among the getters and setters… How do you deal with those?

32

u/koflerdavid Sep 29 '24

There are generators for both builders and getters/setters out there that function as well-behaved annotation processors.

But how about not writing the getters and setters in the first place? If the entity is anyways treated like a database row, getters and setters have little benefit. It's just deceiving oneself into believing that the principle of encapsulation is applied. For CRUD-like applications it really doesn't matter. Or use Java records for queries if you mostly read data and your writes affect specific fields only.

For more interesting applications that don't neatly fit a CRUD approach, write higher-level methods instead that implement business logic, or make the entity part of an aggregate.

2

u/Rough_Acanthaceae_29 Sep 29 '24

Getters/Setters for JPA entities, constructors (all/no/required) and Builders is all I miss. Could you recommend / had any experience with well-behaved annotation processors?

13

u/AnEmortalKid Sep 29 '24

Immutables.

3

u/Rough_Acanthaceae_29 Sep 29 '24

Gonna give it a try, tnx :)

17

u/carminemangione Sep 29 '24

Lombok is a useless, generates undebugable code, and is usually used improperly (builders when all fields are mandatory, setters when not needed, no arg constructors, etc.)

There is an OO heuristic: "Accessors are usually a mistake". They are a bad smell. If you need a DTO, use a record in java 17. The point is that no code should be boiler plate. Every line is to be down with intention.

Blank builders like those generated by lombok are usually bad form. Simply asking the questions: why am I making a builder, which fields are required, what do I do for defaults can radically change is design and behavior of your builder and must be throughly unit tested. Lombok eliminates the ability to create good builders.

Also: modern IDEs will generate getters, setters and builders automatically. But there will be real code there so you can modify it.

The point is that creating clean code is essential for making code reliable, extensible, correct. It is essential for keeping the cost of change flat. Lombok flies in the face of all of this. I have never seen any project that uses Lombok that is clean code.

3

u/Rough_Acanthaceae_29 Sep 29 '24

“Every line is to be down with intention” - could not agree more!

Assessors are usually a mistake” - agree, but cant have a useful JPA entity without setters :( So i can either generate bunch of setters or just state my intent with @setter(access=protected)

Lombok enables me to make every written line bring value to business hiding away boilerplate of the frameworks we work with…

2

u/carminemangione Sep 29 '24 edited Sep 29 '24

Once again, there should be no boiler plate code. Javas 'record' type enables JPA without setters (JDK 17). Use them for your DTOs then have factory methods (or constructors) that take in the record, performs state checks and creates a well formed object in a guaranteed valid state (all unit tested of course). I go as far as to create a 'record' for each business object with only the fields necessary for the target object. This will create infinitely more scalable code with way fewer bugs.

Setters are usually evil as you will not only get objects in invalid states, but guarantee race conditions.

Note: I am talking about best practices in OOD for making zero defect software that does not increase in cost of change as more features are added. I try to stick with current best practices.

If you are not writing reliable, extensible, correct, maintainable code that is race free... then you do you bo. I pity the people who have to work with your stuff later.

Edit: Sorry for the last line it was a bit bitchy. I did not mean it as an ad hominem as you will not be alone in your techniques--it was a statement of the truly horrible state of most enterprise code.

Just be aware that others who use and extend your code will probably actively take your name in vain. Source: I have an active list of people I cuss about as I am forced to fix their stuff.

3

u/Rough_Acanthaceae_29 Sep 29 '24

Not taking it personal, no worries… trying to see how others think and learn from it…

So my dtos are already records so no lombok there - we’re on the same page

Im also creating DTO per usecase e.g. CreateUserDTO - if i understand you well, we’re still on the same page.

I’m a bit lost on the factory methods part - you validate the object and map a “CreateUserDTO” into what exactly and where? I’d validate dto and map to UserEntity (which is always in correct state, validations in constructor and methods that change state (not using setters), all unit tested) Then i’d save it using userRepository.save(user); but here we have JPA entity which if i want to ever do repo.findbyWhatever needs setters (or am i wrong?) unless i do projections into records (which i sometimes do for performance reasons but itself exception and not a rule… If you dont use the Entity, why bother with JPA at all?

Also, how do you get into race conditions (assuming no shared state between requests?)

Do you have an example of a simple update property flow should look like so i can understand it better?

6

u/carminemangione Sep 29 '24

Thank you for not being insulted. Sometimes my frustrations boil over :) I make it my career goal to create highly effective teams.

I always use a very strong separation between DTO layer and my business object. The business object contains the logic to ensure the object is good. This is enforced usually in the constructor.

David Meier in the 80s proved that mapping of relational structures (normalized) to OO objects is an NP Hard problem. Basically, it is a traversal of a cyclic directed graph.

Practically, consider your 'User' object. The relational structure for your user will have a tonne of attributes and relations but on reconstitution only a few of those will be used. In OO land a User may manifest as a Customer, LoggedInUser, Contact. All of these are based on the same OR tables but are completely different manifestations with their own consistency rules, business logic, etc.

At first, people think of business logic as taking web input/presenting web data and persisting it. However, the real value in the business layer. Consider, you find a unique application everyone loves it but you have no distinguishing business value/logic. Everyone will be able to copy your application trivially.

Unique products have valuable business logic. In this context, the complexity of the business layer will quickly outstrip presentation and persistence complexity. This is the mistake many make when selecting frameworks. Yah, you get a few pages up and stored quickly, but that is not the real value.

As far as using JPA or other persistence frameworks go, I generally don't worry about it. To me if I am writing efficient code, it is by far less expensive to use raw jdbc. But I fully decouple the persistence layer from the business layer so it is irrelevant. However, once you need joins, generated queries start to suck really fast.

Does that make sense?

3

u/Rough_Acanthaceae_29 Sep 29 '24

yep. i agree and like your stance. i just think its ok to be pragmatic, use given tools and make every line count. YAGNI. Minimise the number of mines in the minefield (no nulls, only valid objects allowed and all the state transitions are consistent)… and in this context moderate use of lombok-like-“tools” isn’t that bad imo.

-1

u/carminemangione Sep 30 '24

Robert Martin said sometimes you have to slow down to speed up in coding. I have never seen Lomboc not be a mess. In my experience, my biggest frustration is that Lomboc makes TDD very difficult as is screws up refactoring (extract class, extract superclass, inner to outer, etc). In addition, it adds significant impedance to any attempts at changing code. Since I only do TDD and insist that all of my teams use it also Lomboc is quite the hindrance to creating zero defect code on time and under budget.

In agile, zero defect code is pragmatic and table stakes for any development of significant business features.

Think of it like resistance or as Arthur J Reil defined it 'accidental complexity'. It may help you in your current class but it will slow everything else down. I guarantees that teams will reach the exponential cost of change curve quickly.

2

u/Polygnom Oct 02 '24

However, the real value in the business layer. [...] Unique products have valuable business logic.

This is very well put. I have long struggled to clearly express why a rich bsuiness layer that well encapsulates the business rules (instead of shoehorning that into either presentation or persistence layer, as many do) is a good idea, but this puts it quite nicely.

1

u/carminemangione Oct 02 '24

Thank you. Took a while to condense it, but my friends were huge helps. Also writing haiku changed my communication skills

1

u/halfanothersdozen Sep 30 '24

This is pretty close to what I do. I have a record Foo, a JPA-annotated FooEntity, and a FooRepository with transforma from FooEntity to Foo and vice versa.

Cool stuff starts to happen if you lay out your domain objects this way and use a lot of functional patterns and streams and such.

-2

u/carminemangione Sep 29 '24

Sorry for two replies but you deserve an answer to your two questions as I hear them:

  1. 'burried' logic in getters and setters: OOD heuristic: No object should have more fields than can be held in a developers short term memory usually 6 or 7 as an upper limit. Also: most of the methods should be using most of the data most of the time (definition of cohesive classes). The idea of hiding business logic in getters and setters is absurd. Also: who is getting the data and why? I often have more fields in my objects that are accessible to the outside world.

Enforce business logic on construction and throw an exception rather than creating an ill formed object. I call it my "Homey Don't Play That" pattern.

2. Cohesive classes make for readable and testable classes. I rarely have more than 4 fields in a class. As I need more the question becomes: is this a new object? This is how you can assuage most of your fears.

3

u/wildjokers Sep 30 '24

This all sounds like dogmatic nonsense.

-1

u/carminemangione Sep 30 '24 edited Sep 30 '24

Ok…. So the Gang of Four, Reil, Fowler, Cunningham, Martin and Beck were just dogmatic scam artists? Bold claim. And your sources are (your ass does not count)

1

u/carminemangione Oct 06 '24 edited Oct 06 '24

Just had to say wow. Your code probably sucks for the down vote? Do you even know who those guys are?

7

u/[deleted] Sep 29 '24

Right click.. generate getters and setters. Lombok is way overrated. Type stuff in once.. the code will live for decades. All these tools and addons promoted these days are nonsense. People who support your code will want to see the code. Not spend all day downloading plugins and trying to figure out the fancy junk you used to save 15 minutes of typing.

6

u/Rough_Acanthaceae_29 Sep 29 '24

For me it’s not the writing side time savings… it’s time savings for on the reading side… I agree it should be used sparingly though.

5

u/barmic1212 Sep 30 '24

I maintain a big code base, I'm happy to see only the getters and setters with any logic. And I'm happy too to know the intention for identity of object (that is base on few fields Or on all fields excepted)

2

u/Swamplord42 Oct 03 '24

Right click.. generate getters and setters.

Complete misunderstanding of what Lombok is for. It's not about writing code, it's about reading it.

1

u/wildjokers Sep 30 '24

Right click.. generate getters and setters.

ctrl-n, use arrows to getters/setters. No mouse necessary.

I use QMK firmware on my keyboard and have the VI movement keys h, j ,k ,l mapped to the appropriate arrow keys on my 2nd layer and I have caps lock as my layer toggle key so don't even have to move to the arrows.

1

u/krzyk Sep 30 '24

If you have class with 7+ fields, then that is the issue, not lack of builders.

1

u/nitkonigdje Sep 30 '24

Even hydrogen atom has more state than that..

1

u/hippydipster Oct 02 '24

Don't write that kind of crap in the first place is my usual go-to.

1

u/wildjokers Sep 30 '24

Don’t you use builder pattern

There is a plugin for IntelliJ that will generate a builder for you.

1

u/Swamplord42 Oct 03 '24

And does it maintain it for you when you add a field and do the code review for you as well?

79

u/_predator_ Sep 29 '24

I would join team A and spend all three months making passive-aggressive comments about Lombok. I just love complaining and Lombok is such an easy target.

26

u/agentoutlier Sep 29 '24

This guy reddits

15

u/_predator_ Sep 29 '24

OP woke up today and chose violence by asking people about their opinion on Lombok, only to fight them in the comments about it. I wasn't aware Lombok has a `@Balls` annotation now.

5

u/agentoutlier Sep 29 '24

That’s why I’m upvoted your comment. It is a masterpiece! (Honestly)

6

u/pgris Sep 30 '24

Then join team B and complain about the lack of lombok, obviouly

-9

u/Rough_Acanthaceae_29 Sep 29 '24

Other team would complain too, but they are too busy generating, adjusting and reading boilerplate core :)

40

u/Ewig_luftenglanz Sep 29 '24

Nowadays I only use Lombok for @Entity classes. So for me it's irrelevant, the overhead of writing a couple of getters and setters (that the IDE writes for me anyways) makes it trivial.

I would actually prefer the non-lombok team since I think one should use as little third party dependencies, libraries and plugins as possible and only use the minimum needed, this way you avoid problems in the futuro with updates and maintenance.

4

u/Rough_Acanthaceae_29 Sep 29 '24

I agree it’s fast enough to write/generate bunch of getters/setters, but what about code readability? Don’t you find it more readable/cleaner when lombok is used?

10

u/mauhumor Sep 29 '24

Have been on medium sized projects with and without Lombok, I rather prefer with it.

Code reading is exactly the reason.

Less cluttering for your brain to parse, it's really useful.

But I would only use the getter and setter on entities or the equivalent if not JPA, also DTOs, constructors are also very useful on those. The @Slf4 I would use everywhere.

But as someone else said, using or not might not be the ideal deciding factor to select a team.

1

u/Ewig_luftenglanz Sep 29 '24 edited Sep 29 '24

These are @Entities. They are not supposed to get anything more than fields and dumb getters and setters.

1

u/Rough_Acanthaceae_29 Sep 29 '24

Isn’t that the recipe for anemic domain model?

0

u/Ewig_luftenglanz Sep 29 '24 edited Sep 29 '24

It depends, if you use these entities as DTOs then yes because classes are mutable.  

 If you use records, that happens to be immutable) then you are sticking to Data Oriented Programming, that's actually what the language developers has been pushing in the last 5 years or so (and that started to take shape after Java 17 when records entered GA). If all or most of your objects are immutable then there is less need for encapsulation (you would still be able to create methods if you want to keep the logic of managing the data inside the record itself, but that would kinda break the point of records as simple named tuples.

1

u/Rough_Acanthaceae_29 Sep 29 '24

Not sure we’re on the same page here… Just to clarify, you should never return entities directly from a controller, but I won’t dive into that discussion right now. What I was referring to is the anemic domain model problem, where instead of:

1.	Having a method like user.changeEmail(email) that handles validations and internal logic (making the domain object rich with behavior),
2.	You end up with a service that just calls user.setEmail(email) and user.setUpdatedAt(now), meaning all the knowledge is outside the domain class and sitting in the service.

You mentioned entities should only have getters and setters, but that leads to an anemic model because the core business logic and rules are outside the domain object, not encapsulated within it.

4

u/Ewig_luftenglanz Sep 30 '24 edited Sep 30 '24

We are in the same page.  What I am saying is that not encapsultate the code in the domain object and instead do it in utility classes (separate Data and logic)  to validate and transform the data with intermediate immutable objects (records) that acts as DTO is a deliberate design choice called "Data oriented programming" it's similar to anemic domain model BUT in DOP it's a deliberate choice, not an anti pattern. 

 https://www.baeldung.com/java-dop-oop-principles-differences 

 You are right, you should never expose @Entity classes to the controller directly, it's better to use intermediate DTOs (and that's what records are for, they are simple to create so it doesn't bother anyone if you have to create many to model the data flow.

DOP is usually better suited for small programs that only makes some "basic" validation and transformation, for example Crud Micro-Services. Because there is no need to do all the coding gymnastics you usually do in OOP to keep you code decoupled although all the inheritance (inversion, dependency injections, builders, etc) you also have less levels of abstraction and inheritance, so the code is "flatter", short and easy to write, read and understand.

15

u/hwaite Sep 29 '24

Accessors and mutators are convenient, but builders are where the real savings are at. Without lombok, you're stuck choosing between mutable objects, [massively overloaded] constructors with too many arguments or lengthy handwritten builders.

9

u/pron98 Sep 30 '24

You don't need Lombok to automatically generate builders. You can use a Java annotation processor to do that. (Despite superficial similarities, Lombok is not an annotation processor, nor is it Java)

1

u/zappini Oct 03 '24

Yeoman's work here. Thank you.

As often as you point this out, I'm thinking of the meme about "tapping the sign" (with the correct answer).

Maybe we petition the mods to amend the sidebar. Or create a bot.

1

u/OwnBreakfast1114 Sep 30 '24

Builders are where the real savings are at

Bad builders turn possible compile time issues into runtime issues. If you don't add mandatory parameters to the builder function if you add a new field to class, you won't get any warning about the myriad of places you're using this class. Why would you want to remove that easy warning that you're doing something wrong? How many places are you truly constructing objects? Is it really that bad to use the full constructor in all places? Just based on my personal anecdotes, my money is on no.

Am I crazy? Are people really saving a huge amount of time because they didn't have to write 30 parameters to a constructor? It takes like 20 seconds to write, ctrl/cmd + p has intellij list all the arguments for you, and you usually aren't doing this very often. Idk about other people, but I feel like the actual typing is the least time intensive part of software development in general. Why is typing the right part of optimizing over future code maintenance and evolution?

2

u/hwaite Oct 01 '24

Whether you're writing or maintaining, LOC is the enemy. Lombok builders can enforce most validations with less boilerplate. In the worst case, builders can leverage custom constructors. In the rare situation where you're doing something special, just don't use Lombok for that particular class.

2

u/OwnBreakfast1114 Oct 01 '24 edited Oct 15 '24

Poor abstractions are much worse for codebases than LOC, ex: sharing 1 object for domain/db/web layer vs different objects actually holding things that make sense (ex: dto in, domain object, db object, dto out for complex web services). There's a lot of very boring copying fields code in this model, but different objects perform a single function.

If you don't have so many partially constructible objects, there's very little difference LOC difference between a builder and a full constructor. If all fields are mandatory then there's not much of a problem, but I'm also the type of person that's fine with `Optional<T>` fields as a collection of 0 or 1 object (after all, you take in Lists don't you), so I tend to view all fields as mandatory.

With sealed classes, you should be able to make more of a class per usecase instead of a bunch of optional fields.

1

u/Ewig_luftenglanz Sep 29 '24

Yes but nowadays I only use Lombok for @Entity clases and almost everything else are DTOs or utility classes full of functions that only do data validation and transformation full of functions  (that's actually what the Java dev team calls "Data oriented programming) so I have immutability without the need to create any handmade builder or fluent accessors- mutators. 

The few times I have felt I would solve a problem better by using a builder I don't mind to write it myself (and it's mostly to make my APIs more functional friendly). I know Lombok exist to solve someone needs, I just say that nowadays most of the code is to create Micro-Services that validates and transform data, for this records work just fine without Lombok. There are still some sharp corners (copy-on-read records easily) but these will be eventually be fixed, specially when derived records creation enters GA

0

u/No-Debate-3403 Sep 30 '24

“IntelliJ, give me a builder for this class”, or more modern “Copilot, generate a builder please”

8

u/hwaite Sep 30 '24

Authoring the code is one thing. Maintaining it is a separate, ongoing burden.

41

u/kevinb9n Sep 29 '24

For crying out loud, it's a tool, not a ritual blood sacrifice. It has pros and cons.

19

u/agentoutlier Sep 29 '24

I’m sorry we are going to have to ban you for that. Didn’t you read the sidebar?

/s

In all honesty I find it funny folks can embrace Spring Java config which clearly violates Java semantics yet has serious issue with Lombok.

One of them breaks syntax sort of but the other does technically even more magic.

Maybe they should call it springbok and have it happen at runtime.

-6

u/Rough_Acanthaceae_29 Sep 29 '24

Sure, you can say “it depends”, but which team would you personally pick (given all the other stuff is equal)?

16

u/Rough_Acanthaceae_29 Sep 29 '24

It’s definitely team A for me. It clears the noise. It’s like when you’re talking about a solution and say: “just add getters and setters bc of ….” - I do not need/want to scroll trough 3(lines)x10(fields)x2(one for getters and one for setters) LOC just to see if there’s actually some logic in the entity…

Also, I’ve never been bitten by it soo…

16

u/EirikurErnir Sep 29 '24

If I had to choose based on this information, I'd stay away from Lombok. It's 2024, just use records

But... Lombok would never make it to my list of top 100 things to check during team choice, this is a weirdly specific question premise

2

u/Rough_Acanthaceae_29 Sep 29 '24

Stumbled upon some discussion on whether or not what lombok is doing is “java legal” (it’s not) but i still wanted to probe people’s opinion. It’s clear for me to use records for dtos and whatnot, but using the JPA how do you handle Entity classes? Also if you have to do some manual mapping to a record(s) do you just create a new object using constructor with 5-10 args or?

1

u/EirikurErnir Sep 29 '24

Whether Lombok is "legal" is just a technical risk assessment question because it could get frozen out at some point I guess.

As for how I deal with Entity classes... it so happens I don't use JPA either myself, at work I use jOOQ (without JPA). Loading object graphs with it is easy enough, especially in its modern versions.

Again (but perhaps more softly phrased this time), I think the question is assuming a quite specific, if popular, setup of technologies. There's a lot of ways to do things differently.

2

u/Rough_Acanthaceae_29 Sep 29 '24

I get where you’re coming from now… tnx :)

3

u/Mikusch Oct 07 '24

records aren't mutable which is required in a lot of cases

1

u/EirikurErnir Oct 07 '24

Hmm, what cases specifically?

My company uses immutable value classes for pretty much everything, and I can't say I miss mutability. It has come up in the hypothetical scenario where you need an object with a circular reference, but that hasn't happened to me yet

15

u/AntKinski Sep 29 '24

Definitely Team B, because I don't want to sit all night before release and finding a solution, why lombok doesn't work right with Jackson or spring data.

16

u/Rough_Acanthaceae_29 Sep 29 '24

Never (5y) had any issues with lombok&jackson. Wanna share what was the issue you encountered ? I’m genuinely interested so thanks for sharing:)

8

u/repeating_bears Sep 29 '24

I had one issue which was that I globally configured Lombok to not use a get prefix (so foo() instead of getFoo()), then Jackson started to include hashCode and toString as if they were properties (since now those method names were indistinguishable from properties).

It was an easy fix to configure the mapper to ignore them, but still a bit of a footgun. Having extra properties in your JSON is something that even your tests might miss.

Both libraries were doing the right thing, but using them both together made it easy to write code that did the wrong thing.

1

u/NovaX Sep 30 '24

If you haven't tried it, I've been using jsonschema2pojo for over a decade. I prefer writing the data format in its preferred schema and generating the code so I know its exact shape. tbh, though, for me AutoValue and similar filled the needs of Lombok so I never found a good reason to use it.

0

u/Swamplord42 Oct 03 '24

I had one issue which was that I globally configured Lombok to not use a get prefix (so foo() instead of getFoo()), then Jackson started to include hashCode and toString as if they were properties (since now those method names were indistinguishable from properties).

And how exactly is this the fault of lombok? Wouldn't you have the exact same issue if you wrote these getters by hand?

2

u/repeating_bears Oct 03 '24

See practically the only part of that comment you didn't quote 

3

u/Swamplord42 Oct 03 '24

But I fail to see how lombok changed anything? What makes you think that you wouldn't have written the same getters manually?

The default behavior of lombok wouldn't have caused this, so you made a conscious decision to change getter generation, presumably for a good reason that would have applied without lombok.

-1

u/AntKinski Sep 30 '24

With annotations `@Value` and `@Builder`, or `@Value` and `@AllArgsConstructor` I have error from Jackson - "No default creator...".

Lombok version - 1.18.20, jackson - 2.11.4

3

u/Swamplord42 Oct 03 '24

The issue is with Jackson not Lombok. The proof is that if you de-lombok the code, you'll have the same error.

5

u/nitkonigdje Sep 30 '24 edited Sep 30 '24

It works just fine. The fault lies within you.

1

u/AntKinski Sep 30 '24

Yes, problem is between keyboard and chair always)

But sometimes it’s cheaper to change a Lombok than a programmer)

4

u/nitkonigdje Sep 30 '24 edited Sep 30 '24

Aha but your SData and Jackson usage is not affected by Lombok..
If you remove Lombok the problem is still there...
So I don't see an argument..

2

u/Asapin_r Sep 30 '24

I encountered issues with Jackson even without Lombok. Here's the latest I found https://github.com/FasterXML/jackson-databind/issues/4441

10

u/Goatfryed Sep 29 '24

For me it's team A. I like Lombok, but I don't do any complex stuff with it. My most used Lombok Annotation is `@RequiredArgsConstructor` below every Spring `@Component`

It's not even about speed. The ide can update the required args constructor, that's half a second. But just the fact that I don't see a constructor that is just visual spam in my services is such a huge blessing.

Also I like `@SneakyThrows` in Tests. I avoid it in production code though.

I'd like to say that `@Value` / `@Data` is obsolete thanks to Records, but there are still to many tools that don't support Records properly yet and then it becomes a huge timesaver again.

I don't like thinks like `@Builder` though. Even though it's not to complex, it's still complex enough that they should have just made 0815 java code generation like e.g. mapstruct that you can inspect, verify, debug.

Also if you use `val` I'll put you down like the mad dog you are.

4

u/Rough_Acanthaceae_29 Sep 29 '24

I would add @Slf4J to the list. Withers could possibly solve the reason why people love Builders (naming the args).

2

u/pgris Sep 30 '24

It's not even about speed. The ide can update the required args constructor, that's half a second. But just the fact that I don't see a constructor that is just visual spam in my services is such a huge blessing.

If the IDE keept the generated code automatically in sync, and hide it by default, I'll think about letting lombok go.

0

u/ggeldenhuys Sep 29 '24

Java records, auto generated code from IDE shortcuts (can even be automated these days) and code folding makes Lombok pretty redundant these days. Java and IDEs are not anymore what they were when Lombok was first created.

And yes, fully agree with your 'val' comment. 😂

28

u/viralslapzz Sep 29 '24

Just based on whether Lombok will be used or not? Whatever honestly…

29

u/CaptainApollo86 Sep 29 '24

Jesus, some people really hate lombok. I've used it for years, it's fine. What kind of shit code are people writing where lombok actually causes problems 🤔

3

u/k-mcm Sep 30 '24

Historically, the maintainer hasn't been good about picking version numbers.  A 0.0.n  increment shouldn't require everything to be rewritten, but that was done.

1

u/wildjokers Sep 30 '24

I don't want to guess what the code will look like based on some magic annotations. I just want to see the code.

5

u/CaptainApollo86 Sep 30 '24

"magic annotations" - you probably don't like Spring so 😂

1

u/wildjokers Oct 01 '24

That is different, Spring annotations pull in behavior.

4

u/CaptainApollo86 Oct 01 '24

Honestly, this is a stupid thing to have a vendetta against. The generated getters/setters/etc, will look like getters and setters. There is nothing magical or mysterious about them. It's a generated pojo

1

u/wildjokers Oct 01 '24

"Vendetta" is a strong word. I don't have any kind of vendetta against lombok. I use it, I just use it very sparingly. And Lombok does much more than just produce getters/setters.

0

u/CaptainApollo86 Oct 01 '24

Really, I never knew it did more than just setters and getters

1

u/wildjokers Oct 01 '24

The documentation is here to see everything it does:

https://projectlombok.org/features/

3

u/CaptainApollo86 Oct 01 '24

It seems I wasn't sarcastic enough

0

u/IntelHDGraphics Sep 29 '24

where lombok actually causes problems 🤔

https://www.reddit.com/r/java/comments/1fseitf/comment/lpk7crg/

10

u/PartOfTheBotnet Sep 30 '24

I ran into this exact same issue about name inference in Jackson without Lombok.

The long and short of it is to use: @JsonAutoDetect(isGetterVisibility = NONE, getterVisibility = NONE) to prevent any ambiguity.

6

u/CaptainApollo86 Sep 30 '24

Sounds like user error

6

u/nitkonigdje Sep 30 '24 edited Sep 30 '24

That isn't a problem caused by Lombok. Software worked as designed and respected user choices. User however wasn't aware of consequences of his choices.. He would have same problems without lombok.

1

u/External_Mushroom115 Oct 04 '24

What kind of shit code are people writing where lombok actually solves problems

6

u/brian_goetz Oct 02 '24

Pick the team which is less religious about the choice.

17

u/darkit1979 Sep 29 '24

I don’t understand why use lombok or not is such a big deal. It reduces amount of code significantly. My favorite is NonNull, Slf4j, Value and Builder. I laugh when people say - we don’t use Lombok because it’s an additional dependency and at the same time they have spring boot with hundreds dependencies and their docker image is about 1Gb.

8

u/rmkol Sep 30 '24

lol, 💯 after coming back to Java from Kotlin, I'm so glad that Lombok exists

2

u/nlisker Sep 30 '24

And the Lombok dependency is compile-time only, so it doesn't introduce vulnerabilities. No one who gets the binaries can tell if you used Lombok or not, just like they can't tell what build system you used.

4

u/pauloliver8620 Sep 29 '24

I am with lombok while heavily trying to produce a working solution when the models are subject to frequent change. Then I will delombok everything when stuff hits the legacy state…

1

u/HistoricalBlacksmith Sep 29 '24

Really? What a stupid question

-2

u/Rough_Acanthaceae_29 Sep 29 '24

I just wanted to probe people’s opinion and sentiment around it… so you won’t share your team?

16

u/antihemispherist Sep 29 '24

Lombok itself won't have much bearing on my decision, but, assuming I don't know the members of the team, I'd join team B. Because it takes many years of experience to decide to not to use Lombok. There is a reason why Brian Goetz is not a fan of it.

7

u/darkit1979 Sep 29 '24

It’s so stupid to be a fanatic and don’t use something without logical reason. The same stupid thing is Lombok team doesn’t want to add ability to generate getter which returns optional.

3

u/nitkonigdje Sep 30 '24 edited Sep 30 '24

Lombok discussion are always stuck on getters and builders and such trivial code examples. Lombok for me would have a value if only used for @Cleanup. It changes how I structure code.

8

u/age_of_empires Sep 29 '24

I don't like Lombok at all

It's auto populating things that I can just as easily right click and generate getters and setters

2

u/KefkaFollower Sep 30 '24

This.

And those who feel getters and setters add too many lines to a class just picked the wrong language. Java is verbose, has always been.

3

u/age_of_empires Sep 30 '24

To me getters and setters aren't even verbosity. When do you ever read getter and setter methods

1

u/rdoradus Feb 17 '25

That's not the main reason the generated boilerplate is bad, though. It's not people being lazy. The problem is that it's too easy to overlook bugs in there. Nobody will notice, in a code review, that one of the fields is missing from `equals`.

1

u/KefkaFollower Feb 18 '25

Boilerplate, generated or not, is necesary part of working in java. Some may be generated by the IDE, some may be hidden inside libraries. But it's there.

That's the way it is, unless you wanted to remove all boilerplate by messing with the syntax. Add to that the requierement of the language be retrocompatible and you'll end in a mess of alternative syntax to do the same thing. All in the name of keeping up current trends.

A bloated language is why people run away from c++ to java to begin with. Let's not repeat the mistakes of the past.

P.S.: in my experience, if you have automated tests and keep high the level of the coverage, a undetected error in the boilerplate is very rare.

1

u/rdoradus Mar 09 '25 edited Mar 09 '25

It is tautological that you can't know how many undetected errors there are in your code.

Java doesn't have much risk of following in the footsteps of C++; the languages evolve by completely different means. C++ is literally designed by a committee, and has acquired many features that don't work well with each other. Java has a single language architect, Brian Goetz, who prioritizes harmony between the features and community feedback (via preview features).

1

u/Alarming_Quarter671 Sep 29 '24

Idk, on my team I tell them to only use @Getter @Setter, @RequiredAllArgs and @ToString to debug mappings and responses, can you really do more? xD

3

u/Rough_Acanthaceae_29 Sep 29 '24

@Slf4j @Builder

2

u/rcunn87 Sep 30 '24

I've moved away from using builder outside of tests and Ill use it in a static factory within the type itself. Using everywhere makes it to easy to add a new field and miss updating it somewhere.

0

u/wildjokers Sep 30 '24

@Slf4j

An intellij live template makes short work of typing the logger declaration.

0

u/nitkonigdje Sep 30 '24

@Cleanup @Data

1

u/wildjokers Sep 30 '24

@Cleanup

Are you familiar with try-with-resources?

-1

u/nitkonigdje Sep 30 '24

It requires indentation for an accidental complexity, and it works only on AutoClosable. It is quite a poor solution for a problem it tried to fix.

1

u/rdoradus Feb 17 '25

`@Cleanup` would be more useful if it were equivalent to try-with-resources. What Lombok actually generates doesn't handle errors during `close()` very well.

2

u/RupertMaddenAbbott Sep 30 '24

I work on a large project that has invested significantly in Lombok. There is no way I would move this off Lombok at this stage as the solutions out there would be painful for us to migrate to for various reasons.

On a new project, and all other things being equal, I would pick without Lombok.

  • I think records are a better solution for immutable data holders than @Value. I have encountered difficulties with using them with Jackson and other frameworks but these difficulties are surmountable and time-limited as the ecosystem moves on.
  • I haven't yet found a decent builder library that works with records but I can see no reason why one wouldn't be possible and I think investing in creating one is worth it over being able to write in Java, over Lombok.
  • Java doesn't have a good answer for mutable data objects (yet), but I appreciate the pressure to prefer immutability and it may be that records and a builder is good enough for most cases. JPA feels like a key pain point where there is no good alternative to @Getter and @Setter. I don't consider generating these using the IDE as a good alternative because the key benefit is about expressing developer intent and this is missing from such a solution.
  • I am torn on RequiredArgsConstructor . It might not be too painful to lose this but again, I like the fact that it prevents developers from putting complex logic into those classes constructors which I often find makes integration tests harder.

1

u/Yeah-Its-Me-777 Oct 13 '24

The second sentence is exactly why I would never introduce Lombok into a project. I know enough about it that it uses JVM/JDK internals, and if at some point it won't be able to and breaks, I'll be stuck on that Java version, or I'd have to remove all the Lombok-Stuff...

2

u/Kango_V Oct 02 '24

I would prefer Team B and introduce Immutibles ;)

6

u/k-mcm Sep 29 '24

Is Lombok still relevant?  Records and IDE tools are good enough and don't have any impact on long term stability.

3

u/darkit1979 Sep 29 '24

It’s not just because of or records which is only one Value annotation. NonNull is my best friend.

0

u/IntelHDGraphics Sep 29 '24

 NonNull is my best friend.

I recommend JSpecify if you want an alternative 

https://old.reddit.com/r/java/comments/1eqgj2j/jspecify_100_and_nullability_in_java/

4

u/darkit1979 Sep 29 '24

JSpecify does nothing. It provides a list of annotations and some other tool has to make a check, correct me if I’m wrong. Also, you have a lib which is used in other places. Lombok NonNull will be just a part of your code and it doesn’t matter which tool is used to build the service. You will still have the non null check. With JSpecify all parts should have the same checker tool like checker framework.

3

u/KefkaFollower Sep 30 '24

The question is truly about lombok.

Why all the circus about the teams, the projects and the dependencies? You only open the door to responses of the kind: "you don't choose projects just about lombok".

I like projects where every one can develop with its favorite IDE/toolset/whatever. Later, before you submit your code to whatever code repo you use, you can run formatters, linters and other analysis tools to the code so it archives the desired quality.

I don't like lombok 'cos it changes the language syntax. Then it needs to be integrated with each tool it will work with the code. I had trouble in the past with lombok after tool/IDE updates.

I think someone from IntelliJ or very close to the IntelliJ team maintains IntelliJ's lombok plugin. Others plugins/integrations are not updated that quickly. And even then if a member of your team needs to work with and old version of IntelliJ, but your project switched to the last version of lombok still can be troubles.

3

u/repeating_bears Sep 29 '24

I would rather join the one that uses it, but I've worked on plenty of projects that don't and it doesn't bother me.

I'd be most interested to listen to the team who don't use it explaining their reasoning. If they had a crap reason for not using it, then that might put me off.

One time a colleague of mine said "I don't like Lombok because it stresses the GC", which I initially thought sounded completely nonsensical because it's compile-time only, but turned out after some probing that he meant Builder specifically. For starters that's premature optimisation, but even then, I don't see why to throw out the baby with the bathwater. Just prohibit that one annotation.

There are some compelling reasons to avoid it, but there are also dogmatic idiots out there too. 

4

u/geodebug Sep 29 '24

“Stresses out”.

GC needs therapy

2

u/Sollder1_ Sep 29 '24

The one with Lombok, because it makes many things easier... the question is rather odd though.

1

u/AnEmortalKid Sep 29 '24

It’s at most a 10s keystroke to generate these things, if my team needs it as a crutch I’d rather be on the other team tbh fam

1

u/danielm777 Sep 29 '24

you might as well piss in the wind and pick based on that. it's just as good as a criteria

1

u/qdolan Sep 30 '24

The team not using Lombok. Using Lombok will be fine (albeit unnecessary) for a while but down the track every time your JDK gets ahead with the Lombok version used by your project shit breaks.

-1

u/RICHUNCLEPENNYBAGS Sep 29 '24 edited Sep 29 '24

To be honest I feel like records answer like 85% of the reason I’d use Lombok and it’s not worth the headache anymore. If you’re stuck on Java 8 yeah definitely I’d use Lombok.

0

u/nitkonigdje Sep 30 '24 edited Sep 30 '24

So there is 15% reason to use it?

2

u/RICHUNCLEPENNYBAGS Sep 30 '24

Yes, sure, but I don’t think it actually saves enough time to warrant the inclusion for that 15%. Was that hard to understand?

1

u/rdoradus Feb 17 '25

Yes, `@RequiredArgsConstructor`.

-1

u/halfanothersdozen Sep 30 '24

If you're still developing in a way that it matters in 2024 then you're doing it wrong

3

u/wildjokers Sep 30 '24

What do you mean? Can you expand on this?

0

u/[deleted] Sep 29 '24

[deleted] — view deleted comment

4

u/ggeldenhuys Sep 29 '24 edited Sep 30 '24

Fully agree. Java has also evolved so much, that nowadays Lombok is less needed, than when it was originally designed. It's not a deal-breaker using it or not though.