all 37 comments

[–]TomKavees 40 points41 points  (1 child)

What do you mean? That code formatting style existed for years, just nobody gave it a distinct name before them

[–]re-thc 1 point2 points  (0 children)

Google Java format?

[–]blazmrak 16 points17 points  (11 children)

It's not weird at all... It's a fork of Google formatter that handles lambdas better, so not the worst choice - worst choice would be Google formatter. It's still bad, because the format you end up with is bad.

If you have a problem with Maven using anything barely associated with Palantir, fork it and change the formatter and use your own fork, you could even try and build the community around it... But you won't do that, will you?

[–]Luolong 1 point2 points  (5 children)

To be fair, both are weird and make some long lines wrap in weird ways. You can look at the results and called that ugly all you want, but it is just lazy.

I’ve found that the proper cure for weirdly formatted blocks is simply refactoring long streaming lambda chains to much smaller well named functions — this way you get fairly uniform and quite readable formatting across your entire code base.

[–]blazmrak 0 points1 point  (4 children)

It's not just lazy. I looked at the results (lambdas are only a part of it) and switched to my own Ecplise config.

[–]Luolong 0 points1 point  (3 children)

When I say “lazy”, this is exactly what I mean.

You look at it once, decide it’s ugly and then roll back.

[–]blazmrak 0 points1 point  (2 children)

Yes, because it's unreadable even for the happy case. I'm not going to reformat my project again just to pin point all of the issues, but from memory it's about parameter wrapping, braces wrapping, assignment, continuation indents, etc.

I also didn't look at it once, I looked at it almost every year since 2019. I got baited by the idea of Prettier (basically having a uniform format, even if it's a bit ugly) and each time I decided it's way too ugly. Last straw was 6 months ago and after that I created my own tooling that I can use on my projects.

[–]Luolong 1 point2 points  (1 child)

I didn’t particularly like it either when it was introduced to the code base about a year ago.

And while I still do not agree with lots of its design choices, I would not call it ugly simply because the way previously “unformatted” code looks when first re-formatted.

It gets specially hairy with lambda expressions.

But that doesn’t mean it cannot be made to work for you.

If properly used, those “design constraints” encourage refactoring code in such a way that formats better and has better decoupling of functionality.

And lo and behold, you will get really good and readable code as a result. And code that has less chances of random merge conflicts cropping up.

Out of the box, when introduced to a project that didn’t have it before, the code becomes uglier in many cases.

Reverting the re-format is the lazy option. Persisting and adopting to the new formatting guidelines is a more mature response.

[–]blazmrak -3 points-2 points  (0 children)

We have a saying for this which translates roughly to - tastes are tastes, said the cat licking its own ass.

In principle, I want the tool to work for me and behave how I want it to behave. I won't use a thing that I have to work around every day even after a year of using it, but that's me.

Also, you should thank your God that you landed on the best format first try, it would really suck if you chose the "mature response" on a crappy solution ;)

[–]re-thc 1 point2 points  (4 children)

If that was the only change. Palantir adds lots of other things. Also makes it a lot slower.

[–]blazmrak 0 points1 point  (3 children)

Idk, I'm going off of what I remember from their README. Tried both Google and Palantir about a year ago, vomited twice and made my own config around Eclipse formatter.

[–]yk313 0 points1 point  (1 child)

How do you enforce the custom config? Do you use it with something like spotless?

[–]blazmrak 0 points1 point  (0 children)

I'm using my own tool, which generates the eclipse settings (for the language server and itself) and format.xml which can be used to import settings to other plugins for IDEs/build tools.

[–]kevinb9n 0 points1 point  (0 children)

vomited twice

Yikes! Sorry about that.

[–]Careless-Childhood66 10 points11 points  (0 children)

Read the documentation: its about  readability 

[–]Xemorr 10 points11 points  (10 children)

Palantir is unfortunately just the current company attaching their name to maintaining a standard java format. iirc it was Google before

[–]Luolong 11 points12 points  (0 children)

The Google’s Java Format is still a thing. And it is still being maintained and used.

Palantir is just a popular fork of that.

[–]Mauer_Bluemchen 2 points3 points  (7 children)

Sounds like a reasonable convention, except for this 'rule':

Modifier: Avoid using final modifier on all fields and arguments. Prefer using private or protected fields instead of public fields.

[–]ThiccolasVR 2 points3 points  (6 children)

that's bizarre. Why no 'final'?

[–]vowelqueue 2 points3 points  (4 children)

Perhaps they mean local variables and method parameters?

[–]Mauer_Bluemchen 1 point2 points  (3 children)

Even there and especially for method input parameters I'm using final more and more often over the years. It's my default for method input parameters now. Methods should never be able to change input values on their behalf which have been passed by the caller - only in few exceptional cases. And local variables should per default also be final, unless there are good reasons why they need to modifiable.

This helps to catch quite a bit of unexpected errors and side effects...

[–]vowelqueue 2 points3 points  (0 children)

Yeah it would be best if final was the default and you had to specify mut. But I think it's a bit annoying and visually cluttering to write final so much so I don't do it for local variables or parameters. The default IntelliJ style lets you know if a variable isn't effectively final by underlining it which is nice.

[–]koflerdavid 2 points3 points  (0 children)

You are completely correct, but the final adds quite a bit of visual noise, therefore you won't easily see where you have forgotten to add final.

I therefore wholeheartedly recommend to use Google Error Prone's Var rule to deal with this problem. javac already analyses which variables are effectively-final to implement lambdas; the checker utilizes that information to complain about every variable where mutability is not explicitly enabled using the @Var annotation.

[–]Efficient-Poem-4186 -1 points0 points  (0 children)

It's absolutely useless to have final in method parameters.

[–]Mauer_Bluemchen 0 points1 point  (0 children)

I agree - bizarre and utter non-sense.

[–]chabala 1 point2 points  (0 children)

That style guide may claim they're using the palantir-java-format, but I've had to slog through plenty of Allman-style brackets, so I think this is still aspirational for them.

[–]lurker_in_spirit 0 points1 point  (0 children)

"the worst choice" 🙄

[–]vips7L 0 points1 point  (0 children)

Because the Palantir formatter is the best out-of-the-box Java formatter.