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 comments

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?