Replies: 6 comments 2 replies
-
+1 for the first personally. One of the benefits is it's easier to see chains of conditions. Compare (notice that one of them is different is more easily seen in the first form): return limitNode.getCount() == limit
&& limitNode.isWithTies() == !tiesResolvers.isEmpty()
|| limitNode.isPartial() == partial
&& limitNode.requiresPreSortedInputs() == !preSortedInputs.isEmpty(); return limitNode.getCount() == limit &&
limitNode.isWithTies() == !tiesResolvers.isEmpty() ||
limitNode.isPartial() == partial &&
limitNode.requiresPreSortedInputs() == !preSortedInputs.isEmpty(); But it seems like we are mostly using the 2nd form today (by a large margin). # Install ripgrep and run
# 1st form
$ rg '^\s+(&&|\|\|)' --type java | wc -l
329
# 2nd form
$ rg '(&&|\|\|)$' --type java | wc -l
1613 |
Beta Was this translation helpful? Give feedback.
-
Yeah. But if set a new rule then we can migrate over time to a direction we want.
I think the example code requires a cleanup. Mixing |
Beta Was this translation helpful? Give feedback.
-
That was the point - with the trailing form it's difficult to notice that something might be wrong. (the original code uses all |
Beta Was this translation helpful? Give feedback.
-
What does intellij write when generating equals? |
Beta Was this translation helpful? Give feedback.
-
For me it does not format this.
|
Beta Was this translation helpful? Give feedback.
-
Indeed. intellij doesn't output linebreaks for me either. |
Beta Was this translation helpful? Give feedback.
-
Where to put binary operator in multiline java expression in the code.
I prefer option 1 as it a second line starts with the operator so it is clear that it is continuation. It is similar to:
Beta Was this translation helpful? Give feedback.
All reactions