News for hackers. Stuff that matters.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by wpollock on Tuesday September 26, 2023 @11:52AM (#37661159)
Will this enable lombok officially?
Re:JEP 457: Class-File API for Parsing, generating, transfor... by cogman10 on Tuesday September 26, 2023 @11:58AM (#37661263)
Lombok's headaches are because they are touching Java compiler internals to accomplish their magic. This won't fix that.

Lombok wouldn't be nearly as troubled if it was just doing simple bytecode manipulation.

If lombok wants to stop the pain, then they'll need to stop reaching into internal APIs. They'll possibly need to remove a few features (like some of the `private final` work they are doing).

In other words, you can expect lombok to be a headache for years to come. (Maybe consider not using it? That'd be swell. Speaking as someone that curses lombok everytime jdk updates roll around.)

Re:JEP 457: Class-File API for Parsing, generating, transfor... by the-smug-one on Tuesday September 26, 2023 @12:21PM (#37661606)
Why isn't Lombok just written as a pre-javac pass? javac(lombok(srccode)). Just gotta keep that parser alive and up to date, which open source IDEs also must so they're probably available.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by tmccrary55 on Tuesday September 26, 2023 @01:00PM (#37662306)
It's easier (read more reliable) to manipulate bytecode or other internal representation than the source.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by aardvark179 on Tuesday September 26, 2023 @02:08PM (#37663426)
Manipulating the AST would be fine, but Lombok pretends to be an annotation processor (which can generate new classes, but not alter the semantics of the class being processed). They could create lombokc and crack open the internals of the Java compiler as much as they like, but this would mean admitting they are really Java, and they don’t seem to want to accept that.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by exabrial on Tuesday September 26, 2023 @12:13PM (#37661497)
Lombok is a compiler extension, where this is an API for the JVM. So two very different things. Think of Lombok/compiler extensions as #include directives in C... things that happen at compile time. This API is for writing programs at runtime, past the compile phase.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by pron on Tuesday September 26, 2023 @06:40PM (#37666793)
Lombok is not a compiler extension. Compiler extensions, aka annotation processors, are offered only specific capabilities that ensure that they preserve the Java language specification. Particularly, code that compiles successfully with an extension also compiles without it (perhaps requiring other classes to be available) and it compiles down to the same bytecode. Annotation processors are used to implement pluggable type systems (e.g. https://checkerframework.org) or to generate other classes (e.g. https://immutables.github.io/).

Unlike compiler extensions, Lombok compiles source files that do not conform to the Java language specification. Lombok is an alternative Java Platform language, like Clojure or Kotlin or Scala, except that it's a superset of the Java language. However, rather than forking `javac` source code and modifying it to compile Lombok source files, the Lombok compiler modifies `javac`'s operation by hacking into its internals and modifying them as it runs to compile Lombok sources rather than Java sources.

Having alternative Java Platform languages is perfectly fine. The problem with Lombok is that it doesn't present itself as such but as a library or a compiler extension even though it violates the Java language specification in ways that compiler extensions are forbidden from doing.

Re:JEP 457: Class-File API for Parsing, generating, transfor... by alserio on Tuesday September 26, 2023 @11:00PM (#37669392)
Last time I checked, admittedly several years ago, Lombok was abusing the fact that the AST esposed to the annotation processors was mutable (exposing a deep immutable view over a complex data structure is not something that you do easily nor efficiently in Java to this day, so I'm not blaming javac here). The compiler estensionions were not really forbidden in any meaningful way to do what Lombok is doing, and given the difference in tooling and effort required for a new language I don't really blame them either. That said, going against the whishes of the JSL has its risks, but I can understand Lombok's choice. I still push against Lombok in the projects I work on since how it works makes me unconfortable.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by pron on Wednesday September 27, 2023 @04:04AM (#37671570)
There's nothing wrong with offering an alternative language or even with basing another language's compiler on javac. What's wrong is the misrepresentation of what they're doing and how they try to hide the technical risks involved from their users. Don't call yourself a Java library if you're really a different language that's very much not Java; don't say you're a compiler extension if you bypass the compiler extension API and change its internals to turn it into a compiler for your new language. Their choices are fine; telling users you've chosen something else is not.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by xxs on Tuesday September 26, 2023 @01:21PM (#37662669)
Lombok should not be touched, esp. since records have been available. Morealso, lombok is just a sugar coating during compilation time.

Even before records, just use public final fields, and be done with the getter/setter nonsense. (IDEs do a good job of offering options for toString(), and c-tors)

Personally, I consider lombok one of the better anti-patterns widely used.

Re:JEP 457: Class-File API for Parsing, generating, transfor... by javanonymous on Tuesday September 26, 2023 @02:40PM (#37663885)
Lombok can be used for more than just getters/setters.

I personally use the @Builder annotation on records with more than 3-4 fields. I find it much more readable than a long list of arguments to the constructor.

I also use other annotations, but I could live without them if a future version of Java provides a builder-like pattern (or named arguments)

Re:JEP 457: Class-File API for Parsing, generating, transfor... by bafe on Tuesday September 26, 2023 @04:15PM (#37665243)
Re:JEP 457: Class-File API for Parsing, generating, transfor... by jmaker on Wednesday September 27, 2023 @06:45AM (#37672823)
Totally, and the With annotation is a bliss. Hope to have it at a syntax level someday, just like in Kotlin. In addition, you can decompile Lombok annotations straight into your code proper and change what you need, Builder methods for validation, say. Lombok is great for DX, especially if you have experience with more recent languages.
Re:JEP 457: Class-File API for Parsing, generating, transfor... by ImprobableTruth on Tuesday September 26, 2023 @05:26PM (#37666007)
Records are the way to go, but there are many situations where the ecosystem doesn't work with them e.g. if you're stuck using something like Hibernate.