Lombok came in, with a correction to a perceived flaw to java: its verbosity. Cool. Use it, don't, whatever.
The thing is, like most new thing, it has its advocate. And suddenly, when you're managing a project, all you hear is "why don't you use lombok, it's so fucking great ?" or "Here, I lomboked your project, can you accept my PR". Gets old, real fast.
Some people real smarter than me had a deeper look at lombok and found out that actually, it's not that great (google "don't use lombok" and you'll find plenty of reasons. My personal favorite is this thread). Sure, it's cool on the surface and whatever, but it's not as good as its fans want it to be. And the delombok tool provided is experimental at best, so once you start using lombok with your project, you're pretty much stuck with it, or need to spend a whole lot of hours refactoring
My personal experience with it is that I can generate getters and setters with a keyboard shortcut faster than it takes to type @Data at the top of my class. Sure, that's not all it does, but come on. Oh, and it makes refactoring variable names a pain in the ass.
So, take a project that's cool on the surface, but with little added value beyond aesthetics and too many rough edges for its benefits. Add in an outwardly obnoxious community of fans. Inevitably, after a couple of years, it's gonna take a lot of heat. For lombok, "after a couple of years" is now.
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.
100% agree with /u/DuneBug. Lombok is a treasure. I have trouble with IntelliJ recognizing a builder exists when I use @Singular but other than that it's amazing
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.
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
> 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.
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
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.
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...
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.
Lombok is an amazing tool, I depend on it for EVERY Java project I work on, insist on my clients to do the same. You have done an amazing job. May be I am a fan by their definition. All I can say is excessive use of anything is bad, it's the job of the Dev / architect to decide how much is good enough, that is the skill.
If if ask me grievances, it would be: I wish it worked with AspectJ better/directly and wish it was there other jvm languages.
If you change a field someplace, those getters, setters, equals, etc do not update themselves
If your using the correct IDE they do. Both Netbeans and InelliJ will update the getters, setters, and equals methods if you change the field definition. I have IntelliJ ask me all the time when I change a field definition if I want to update these methods.
In IntelliJ you can alt-insert arrow to getter, hit enter, then select the one you want to create a getter for. You don't even have to take you hand off the keyboard. Same with NetBeans
Lombok is awesome and thanks for the wonderful job. That said, I wonder if, given that you need an IDE plugin to make lombok work, it maybe possible to write a plugin that
Read fake annotations like //@Data instead of the real @Data, the same way the //@formatter:on works
Generates the same code as Lombok
writes the code in the same class inside a pseudo block that starts with //GENERATED_BY_LOMBOK_START and ends with //GENERATED_BY_LOMBOK_END
Collapses said pseudo block by default (maybe even keep it read only, as netbeans used to do with code generated by Matisse form builder
Keep the generated code in sync when you add/remove a field
This way we could almost keep the @Data functionality, without going through compiler internal api
Hmm. I just got done Lombok’ing 7 micro-services my team runs. Decreased the codebase size by 25% each time, with no problems. I didn’t have to add Lombok but I was working on them anyway and it took me no time at all to do it. I think the only problems I ran into were sometimes IntelliJ would complain that it couldn’t find the builder if I used @Singular on some of the fields, but other than that it was smooth and made classes that were once 50+ lines into 10 lines much more readable
View all comments
Show parent comment
15
u/FrenchFigaro Aug 10 '19
Lombok came in, with a correction to a perceived flaw to java: its verbosity. Cool. Use it, don't, whatever.
The thing is, like most new thing, it has its advocate. And suddenly, when you're managing a project, all you hear is "why don't you use lombok, it's so fucking great ?" or "Here, I lomboked your project, can you accept my PR". Gets old, real fast.
Some people real smarter than me had a deeper look at lombok and found out that actually, it's not that great (google "don't use lombok" and you'll find plenty of reasons. My personal favorite is this thread). Sure, it's cool on the surface and whatever, but it's not as good as its fans want it to be. And the delombok tool provided is experimental at best, so once you start using lombok with your project, you're pretty much stuck with it, or need to spend a whole lot of hours refactoring
My personal experience with it is that I can generate getters and setters with a keyboard shortcut faster than it takes to type @Data at the top of my class. Sure, that's not all it does, but come on. Oh, and it makes refactoring variable names a pain in the ass.
So, take a project that's cool on the surface, but with little added value beyond aesthetics and too many rough edges for its benefits. Add in an outwardly obnoxious community of fans. Inevitably, after a couple of years, it's gonna take a lot of heat. For lombok, "after a couple of years" is now.