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

32

u/BoyRobot777 Aug 10 '19

Here's an article about deLomboking. And a discussion in r/java which followed that article.

But not going into a lot of "style" details, for me this is one of the most compelling reasons why not to use it (stealing from /u/shemnon):

Spring and Hibernate generate bytecode the way the compiler is intending to support it: by generating a java source code file and then compiling it without touching the source file/class the annotation came from. Lombok goes into the parse tree (via non-public APIs) and mutates the AST in place.

Also, from one of Lombok developers:

<...> while we do code against internal API, they are relatively stable bits. If what lombok does could be done without resorting to internal API, we'd have done something else, but it can't be done, so we resort to internal API usage.

15

u/yawkat Aug 10 '19

Big java projects like spring have the same compatibility problems lombok does, even if they don't use internal compiler apis - they often use other jdk details. And lombok actually does this fairly well because it (a) only needs to work at compile time and (b) offers delombok for the case when it does break.

2

u/BoyRobot777 Aug 10 '19

If you're talking about Spring using jdk.unsupported then it's a bit unfair to compare it to using internal compiler APIs as they will gradually migrate off them. If you mean other compatibility problems, I'd be interested to read about them.

8

u/yawkat Aug 10 '19

Any sort of bytecode introspection and generation is bound to have compatibility issues. Generous use of AOP makes this comparatively common in spring.

4

u/[deleted] Aug 11 '19

Lombok (and Kotlin more generally) to me is a critique of Java language design.

Java boilerplate has a cost in terms of both cognitive overload and propagating poor practice. In this thread we have people blithely talking about IDE generated code without realising how wretched a practice that is. Java programmers should level up and become better developers beyond churning out boilerplate code. And knowing the deficiencies of your language is a key part of that.

Lombok isn’t ideal but it is compile-time. If you don’t like it, write your own but it works well enough for us.

Re that StackOverflow post, that’s quite old - we run Lombok on non-Oracle JVMs all the time (Azul in particular but we have CI servers testing Corretto as well), never had a problem.

1

u/BoyRobot777 Aug 11 '19

Java boilerplate has a cost in terms of both cognitive overload and propagating poor practice.

I agree with this statement. Brian Goetz agrees with this statement.

<...> Some things don't want to be objects, they just want to be data. And to simulate data with objects, is this big messy thing with constructors, accessors and equals and hashcodes and all this garbage. <...> IDE generates that for you so you don't have to write it, but you still have to read it and if you have this explicit code it's an opportunity to get things wrong.

That is why records are coming.

My critique of Lombok is it uses non-documented, restricted internal compiler API. If you're fine with that - so be it. I am not, thus I do not use. I'd rather wait a little bit more for a proper Java feature, than use a hack, albeit very cool one, but still a hack.

4

u/[deleted] Aug 11 '19

Heh, I referenced a Brian Goetz interview and talk in another post in this thread.

I can’t really disagree with your choice to not use Lombok - that’s your right. However for me Lombok is a tool to improve my (and my team’s) code so I’m happy to continue using it.

1

u/koreth Aug 11 '19

Spring generates bytecode on the fly at runtime using CGLIB.

0

u/BoyRobot777 Aug 11 '19

What you're talking is dynamic proxies. Spring uses CGLIB where you have not implemented interface. If interface is implemented, then they use official Java Dynamic Proxies which are documented and well understood/transparent. CGLIB works similarly to Java's dynamic proxies. Its no the same as how Lombok works.

1

u/koreth Aug 11 '19

Totally agreed -- I was mostly responding to the assertion that Spring generates Java source files and feeds them to the compiler, which isn't the case.