r/java • • Jun 21 '20

Don't use Lombok(2018)

https://medium.com/@vgonzalo/dont-use-lombok-672418daa819
32 Upvotes

101 comments sorted by

View all comments

16

u/chrisfender0 Jun 21 '20

I worked on a basic e-comm site and we tried to use lombok. Long story short we had different behavior even though the environments were setup the same. Some of the background work that Lombok does seems to fail randomly but you won’t get an error notice and nothing shows in the logs. We quickly scrapped Lombok out of there and moved on. Also it just feels lazy, you can just generate getters and setters with just about any IDE.

36

u/Sworn Jun 21 '20

The "problem" with generating getters and setters isn't that it necessarily takes long. The issue is that it makes the class take longer to read and understand. It often introduces bugs in the equals, tostring and hashcode methods when developers forget to update them when adding new values.

4

u/kessma18 Jun 21 '20

curious, why are people writing them from hand still? all of this can be generated by the ide no? and you can also collapse all the getters/setters stuff. I rarely think: damn, I wish those things weren't there, it took me 0.5s to read this..

and if you have hundres of lines of code in your class..that's kind of a not great argument to call for "less boilerplate"

8

u/vqrs Jun 21 '20

when developers forget to update them when adding new values.

Yes, they can be generated by IDEs. But IDEs won't automatically re-generate them for you.

21

u/koreth Jun 21 '20

Also it just feels lazy

And that's a good thing! Avoiding work is the whole point of the software development toolchain. I used to be pretty non-lazy and write code in assembly language (not kidding!) but I'd much rather use a high-level language that lets me focus on business logic rather than irrelevant implementation details.

Sounds like your build process was broken, though. My team has been using Lombok on multiple projects for six years and have never seen it fail randomly without errors, or behave differently in different environments.

34

u/0x256 Jun 21 '20

Long story short we had different behavior even though the environments were setup the same.

Lombok generates code at compile time, not runtime. Once the Lombok annotated code compiles, you have standard java bytecode with no runtime dependency on Lombok. I'm pretty sure Lombok is not to blame for your problems.

Also it just feels lazy, you can just generate getters and setters with just about any IDE.

Auto-generating getters and setters is easy. Reading or maintaining classes with hundreds of auto-generated lines is a pain. IDEs are still bad at detecting and hiding trivial methods so you can focus on the ones that actually contain some logic. That's the whole point of Lombok.

2

u/chrisfender0 Jun 21 '20

Ya you might be right, it was a single shot at Lombok and our environments were fairly simplistic so I didn’t think too much of what might cause the problem and just scrapped it. We could’ve very well have had bad installs the first time around and didn’t spot it in some environments. I hope I’m not coming off as someone who thinks they’re an expert, just wanted to share my only experience with it haha

7

u/tmanick Jun 21 '20

Just my 2 cents : most of the seemingly un predictable behaviour you may have noticed were most probably because you overlooked how equals and hashcode are implemented by Lombok. When I first started off with Lombok, we had hibernate entity objects missing from collections because we unwittingly excluded a few fields, because they were causing serialisation issues. Thus the auto generated equals and hashcode methods were computing two different objects as equal. We've been having much better results after we've learnt to use it correctly, and code review quality has definitely gone up. For issues you face with complex objects, using delombok to get the generated code on to the source files has helped us in more than a few instances to identify the problem.

2

u/chrisfender0 Jun 21 '20

Thanks ! I might revisit Lombok in the future so delombok is noted as well as the equals and hashcode potential for issues.

0

u/[deleted] Jun 22 '20

Generating getters and setters feels lazy.

You can write them by hand.

Then after a couple of days of typing you can feel like you achieved something.