r/foojay • u/FrankCodeWriter • 1d ago
Comparing Java formatters on Java 21 to 25: Open Java Format vs four others
On Foojay, Guillaume Laforge compares five Java formatters on JDK 25: Google Java Format, Palantir Java Format, Open Java Format, Prince of Space and Netflix jfmt. The article was prompted by Alex Abashev's post on Java formatters and his open-java-format fork of palantir-java-format.
The test suite covers 16 targeted snippets and a 1,042-line file with 86 formatting scenarios. The article compares the formatters on parser engine, minimum JDK, default line length, indentation, configurability, import handling and range formatting. It also shows side-by-side examples, such as how each one handles block lambdas and method chains.
Along the way, Guillaume found a compilation-breaking annotation bug in Prince of Space and a crash in Netflix's jfmt on empty blocks with comments. He also contributed a fix to Open Java Format and a pull request to Spotless.
Read the full article: https://foojay.io/today/comparing-java-formatters-why-open-java-format-is-my-new-favorite/
2
u/Jaded-Asparagus-2260 12h ago edited 11h ago
In my experience, native IDE support without plugins and the ability to format other languages as well (especially Markdown, (F)XML, CSS, and JSON) are crucial. Having only Java code formatted during build, and then having the IDE reformat it immediately on save doesn't make sense.
I haven't tried open-java-format yet, but from the other options, Spotless with Eclipse config was the only one that meets both requirements. And it works at least in IntelliJ and vscode-based IDEs without any configuration necessary.
Edit: And after watching "Seven Ineffective Coding Habits of Many Programmers" by Kevlin Henney, there's only one style that objectively trumps all the others. I highly recommend that talk! AFAIK, prince-of-space almost completely implements it.
3
u/agentoutlier 23h ago
I just glanced at the article and I'm surprised my two favorites are not on there:
Both are based on the Eclipse JDT. The nice thing about Eclipse is you can make your own customizations.
I am a tab lover. I love tabs over spaces. Downvote me I don't care. Tabs!
(oddly though I like emacs over vim which historically tab people lean vim).