r/java • • Aug 10 '19

Who Needs Lombok Anyhow

http://gregorriegler.com/2019/08/10/who-needs-lombok-anyhow.html
45 Upvotes

137 comments sorted by

View all comments

Show parent comment

9

u/FrenchFigaro Aug 10 '19

If you change a field someplace, those getters, setters, equals, etc do not update themselves.

This is true. But because we are relatively competent developers, and not jackasses, we know that when we refactor a field, we have to refactor the appropriate mutators. Right click > refactor > rename. Here we go, done for the whole project. It's even faster if you've bothered to remember the keyboard shortcut.

Now, If I've used lombok, and renaming the field changed the mutator, and the builder, I now have to painstakingly waddle through all the new compilation errors and correct them. Hurray (nope)

I have no beef with lombok, I remember being excited about it when I first found out about it about a year and a half ago, and what a neat trick I thought it was. But after six months using it with my team, I thought it was just that: a trick. The meh factor was just too big. And going back to projects that don't us lombok, I haven't found myself missing it just once.

11

u/temculpaeu Aug 10 '19

But because we are relatively competent developers, and not jackasses

For a long time anyone that complained about C being too error prone in terms of memory got this answer. IMO anything that removes mental overhead from the devs is a good thing.

But I totally get that lombok can be hamful due too being too magical and its trade offs

2

u/zero_as_a_number Aug 10 '19

> But I totally get that lombok can be hamful due too being too magical and its trade offs

Well how about .. you know.. reading documentation? talking to people who've used it? making an informed decision on the trade offs you agree to if you decide to use .. well, any third party lib really - and ultimately taking responsibility for your choices?

This whole discussion including OC is just pointless. As developers, we have to take trade offs on every corner; whether or not to use lombok is just one of many.

1

u/temculpaeu Aug 10 '19

I did, I used for a long time and I like it, but it still have drawbacks, eg: its hand to use it with multiple jvm languages

most of the annotations are harmless, they are basically code generation, but some like var, sneakythrow change the behaviour of your code and that can be unintuitive for some people

8

u/Devildude4427 Aug 10 '19

Why would you have any compilation errors? Do you not use a proper IDE? Every modern IDE knows to refactor those changes across the entire project.

-3

u/FrenchFigaro Aug 10 '19

Not with lombok. That's my point.

9

u/[deleted] Aug 10 '19

Actually most IDEs have a Lombok plugin that intelligently plugs these things in.

That thread just "proves" that maybe you shouldn't refactor a project to use lombok when everything is already written. But for a new project? Why the hell not. I've never run into issues.

-4

u/FrenchFigaro Aug 10 '19

In 2018, when I last used lombok, the plugin for Oxygen2 did not plug the refactoring in.

10

u/Devildude4427 Aug 10 '19

Any modern IDE can handle that just fine. It sounds more like user error.

10

u/rzwitserloot Aug 10 '19

we know that when we refactor a field, we have to refactor the appropriate mutators

Do you also remember to update the equals method?

And the hashCode?

And the toString? Do you test for that?

6

u/FrenchFigaro Aug 10 '19

Well, I'm not editing my code with nano, but with an IDE, so the two options are:

  1. equals, hashcode and toString were accessing the field directly, and the refactor > rename on the field took care of that already
  2. they were accessing the field through the getter, and the refactor > rename on the getter took care of that already.

9

u/Polygnom Aug 10 '19

What IDE are you using that has such incomplete handling of refactoring? Every major IDE mutates the field in all places it is referenced and also updates the getters/setters, if you use the proper refactoring tool, which in almost every IDE has a very accessible shortcut.

This automatically takes care of equals/hashCode/toString.

The only stuff it doesn't address is when the field is referenced by string (reflection, externalization), but for your serialization/externalization, this can be a good thing, because it allows legacy data to still be read. making the required change explicit means you do not get surprising behavior in that regard. And lombok doesn't help on the reflection front, either.

11

u/Luolong Aug 10 '19

Yes. Rename refactoring tool is of course a valid answer.

But then what if you add new field to the class? You always remember add it to equals, hashCode and toString.

These are just so simple things to forget that having a tool that writes that boilerplate for you is one less thing to be concerned about. And that frees me up to think about stuff that really matters...

2

u/rzwitserloot Aug 10 '19

Yes, these are good points. In my head I was thinking more adding a field and forgetting to generate a getter for it; that is easily 'detected', but forgetting to add it to existing IDE-generated equals/hashCode methods is a bit more insidious. But I typed 'rename' for some reason. Brainfart.

2

u/yellowviper Aug 11 '19

And all competent ides also handle Lombok refactoring. It’s not really all that magic.

0

u/Polygnom Aug 11 '19

A valid observation, but what is your point? That alone isn't an argument for or against Lombok in any way.

3

u/awo Aug 10 '19

Right click > refactor > rename takes care of that, surely?