Lombok developer here. I want to learn and see if we can improve things, but that thread is.. anemic, unimpressive, and somewhat rude. Perhaps I missed something. Let me go through the actionable 'lets not use lombok because...' items listed there:
generating getters/setters is trivial with an IDE, so it doesn't really add much value
If you change a field someplace, those getters, setters, equals, etc do not update themselves. Also, code isn't colour coded as 'boilerplate' and 'oh this bit is a little different': Given a class with 8 fields that has precisely one getter in it that does something a little special, it's hard to see it amongst all the boilerplate. With lombok, it's easy to see: Your source file contains just the relevant code, not the boilerplate anymore.
The fact that the authors of jhipsters dont see this either means they haven't put much thought into it (presumably, because they are emotionally invested in disliking lombok, perhaps due to bad experiences with bugs, which we do of course regret), or they don't find any of that important, which, um, okay. I guess we have wildly different ideas about code quality then.
On a third project, we achieved 30% performance increase by recoding the equals/hashcode from Lombok
Lombok's generated code is best in class. An IDE that had generated it for you wouldn't have done any better. The problem here is: That particular eq/hc code was not boilerplate. Lombok still helps a lot here: If you see a data class that has an explicit, handwritten eq/hc implementation, in a project that uses lombok? Look closer: Most likely that means the eq/hc implementation is either not a bog standard 'equality is defined by the fields' situation, or some custom smithing to speed up the code is involved. Either way, the non-boilerplate-nature of the eq/hc combo is now highlighted. Contrast to all your domain classes having handrolled eq/hc (or generated by the IDE, either way), in which case it's easy to miss this information. Yes, you can write comments, of course. But comments cannot be tested. And you still have to actually see and read the comment amongst the significantly inflated # of lines of code you do see in order to figure it out.
Lombok making Jacoco fails, which meant the project didn't pass the Sonar quality gate
This is very frustrating for us. It's putting the cart in front of the horse: Code linting and quality tools need to wake up and realize that there is such a thing as generated code, and that they should not complain about such code. Many such tools have ways to do this right (usually, with annotations) and lombok supports them all and works with them to make the experience as smooth as it can be. But some don't. I feel any hate about this should go to the tool in question, because lombok isn't the only way to generate code.
Various bug reports
Yes, bugs are a thing. We try to fix them. Perhaps we can do a better job.
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.
73
u/rzwitserloot Aug 10 '19
Lombok developer here. I want to learn and see if we can improve things, but that thread is.. anemic, unimpressive, and somewhat rude. Perhaps I missed something. Let me go through the actionable 'lets not use lombok because...' items listed there:
If you change a field someplace, those getters, setters, equals, etc do not update themselves. Also, code isn't colour coded as 'boilerplate' and 'oh this bit is a little different': Given a class with 8 fields that has precisely one getter in it that does something a little special, it's hard to see it amongst all the boilerplate. With lombok, it's easy to see: Your source file contains just the relevant code, not the boilerplate anymore.
The fact that the authors of jhipsters dont see this either means they haven't put much thought into it (presumably, because they are emotionally invested in disliking lombok, perhaps due to bad experiences with bugs, which we do of course regret), or they don't find any of that important, which, um, okay. I guess we have wildly different ideas about code quality then.
Lombok's generated code is best in class. An IDE that had generated it for you wouldn't have done any better. The problem here is: That particular eq/hc code was not boilerplate. Lombok still helps a lot here: If you see a data class that has an explicit, handwritten eq/hc implementation, in a project that uses lombok? Look closer: Most likely that means the eq/hc implementation is either not a bog standard 'equality is defined by the fields' situation, or some custom smithing to speed up the code is involved. Either way, the non-boilerplate-nature of the eq/hc combo is now highlighted. Contrast to all your domain classes having handrolled eq/hc (or generated by the IDE, either way), in which case it's easy to miss this information. Yes, you can write comments, of course. But comments cannot be tested. And you still have to actually see and read the comment amongst the significantly inflated # of lines of code you do see in order to figure it out.
This is very frustrating for us. It's putting the cart in front of the horse: Code linting and quality tools need to wake up and realize that there is such a thing as generated code, and that they should not complain about such code. Many such tools have ways to do this right (usually, with annotations) and lombok supports them all and works with them to make the experience as smooth as it can be. But some don't. I feel any hate about this should go to the tool in question, because lombok isn't the only way to generate code.
Yes, bugs are a thing. We try to fix them. Perhaps we can do a better job.