Hi Suraj,
We discussed this in the past (I can't find it yet) and we concluded that we
should not allow that.
It's in contradiction with "Code Conventions for the Java^TM Programming
Language":
https://www.oracle.com/java/technologies/javase/codeconventions-statements.html#449
Hence with our recommended conventions as in
https://cwiki.apache.org/confluence/display/OFBIZ/Coding+Conventions
and
https://gitbox.apache.org/repos/asf?p=ofbiz-tools.git;a=blob_plain;f=wiki-files/OFBizJavaFormatter.xml
BTW, I was looking at LoginServices::checkNewPassword. Its signature was
outrageous long (234 chars!), I splitted it by hand.
I wanted to commit it as is but while at it I decided to try to format the
whole class with Eclipse.
I just putt the result as
OFBIZ-11886-format-LoginServices-checkNewPassword.patch under OFBIZ-11886.
I then noticed that Eclipse rightly splits "if single line statements" but does
not add braces, {}. It's not good as it does not follow Sun convention:
Note: if statements always use braces, {}. Avoid the following error-prone
form:
if (condition) //AVOID! THIS OMITS THE BRACES {}!
statement;
With all this said.
* We have tons of single line statements in OFBiz.
* It's certainly part of much of errors reported by checkstyle.
* I don't remember clearly but it seems to me that when we discussed it
last time it was a moot point. Like with return on the same line.
My conclusion is that could be discussed again and I for one I'm not against
changing this rule for 2 reasons:
1. We can't use our current formatter to do it right
2. With a single line statement there are less chances to confuse and fall
in the error-prone form mentioned above
Another option would be to find a way to improve our formatter to do the right
thing (ie add braces when splitting).
My 2 cts
Jacques
||
Le 14/07/2020 à 07:30, Pritam Kute a écrit :
Looks good to me.
Kind Regards,
--
Pritam Kute
On Mon, Jul 13, 2020 at 9:04 PM Suraj Khurana <suraj.khur...@hotwax.co>
wrote:
Hello team,
I have created a ticket https://issues.apache.org/jira/browse/OFBIZ-11886
to allow single line statements during checkstyle, I hope we are fine with
this.
For this, we need to add a module to allow single line statements:
==============
<module name="NeedBraces">
<property name="allowSingleLineStatement" value="true"/>
</module>
==============
Let me know your thoughts on this.
--
Best Regards,
Suraj Khurana
Senior Technical Consultant