You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Jacques Le Roux <ja...@les7arts.com> on 2012/12/07 13:08:36 UTC
Formatting question
Hi All,
This is a personal question not specifically related to OFBiz nor any projects, just curious (and refreshing ;o)
I'm seeking opinion about "one line" vs "multi lines w/t brackets" vs "multi lines w/out brackets" for "if" and "for" expressions
I mean
I personally prefer something like
if (expres) action
than
if (expres) {
action
}
or
if (expres)
action
The reason is that IMO it prevents
1) to type useless brackets (with a French keyboard for instance brackets are not easy)
2) when you have no brackets there are less risks to confuse, and wrongly add lines below action "thinking" they will be part of the action
Of course if the expression in action is long that's another story.
And then I still prefer to put brackets to be sure (but I'm a lot tempted to not put them ;o)
Your opinions?
Thanks
Jacques
Re: Formatting question
Posted by Jacopo Cappellato <ja...@hotwaxmedia.com>.
On Dec 7, 2012, at 1:08 PM, Jacques Le Roux wrote:
> Hi All,
>
> This is a personal question not specifically related to OFBiz nor any projects, just curious (and refreshing ;o)
>
> I'm seeking opinion about "one line" vs "multi lines w/t brackets" vs "multi lines w/out brackets" for "if" and "for" expressions
>
> I mean
>
> I personally prefer something like
>
> if (expres) action
>
> than
>
> if (expres) {
> action
> }
>
> or
>
> if (expres)
> action
>
> The reason is that IMO it prevents
> 1) to type useless brackets (with a French keyboard for instance brackets are not easy)
> 2) when you have no brackets there are less risks to confuse, and wrongly add lines below action "thinking" they will be part of the action
>
> Of course if the expression in action is long that's another story.
> And then I still prefer to put brackets to be sure (but I'm a lot tempted to not put them ;o)
>
> Your opinions?
My preference is:
if (expression) {
action
}
but also, especially if it adds readability, and when expression and action are short, the following is acceptable:
if (expression) action
On the other hand:
if (expression)
action
should be avoided for the reasons you have mentioned.
My 2 cents.
Jacopo
>
> Thanks
>
> Jacques
Re: Formatting question
Posted by Jacques Le Roux <ja...@les7arts.com>.
Thanks Adam, Jacopo,
Actually I was wondering while reading "Java Concurrency in Practice" where Brian Goetz uses
>> if (expres)
>> action
Some co-workers are also using it. I know some (new) languages also use it as at std way.
I totally agree with you Adam about scanning code :/
Jacques
Adam Heath wrote:
> On 12/07/2012 06:08 AM, Jacques Le Roux wrote:
>> Hi All,
>>
>> This is a personal question not specifically related to OFBiz nor any projects, just curious (and refreshing ;o)
>>
>> I'm seeking opinion about "one line" vs "multi lines w/t brackets" vs "multi lines w/out brackets" for "if" and "for" expressions
>>
>> I mean
>>
>> I personally prefer something like
>>
>> if (expres) action
>
> When scanning code, 'sameness' goes into the background. If there are
> differences, it stands out. Differences also make it harder to
> process, as it takes the brain longer to realize it can skip it.
>
> If some if-blocks have brackets, and some don't, then that is a
> difference, and slows down understanding.
>
>> than
>>
>> if (expres) {
>> action
>> }
>
> My preferece.
>
>
>>
>> or
>>
>> if (expres)
>> action
>
> if (expres)
> action
> else
> other-action
>
> This is ugly. Adding additional actions inside the branch(s) is
> confusing, without the {} already there.
>
>
>>
>> The reason is that IMO it prevents
>> 1) to type useless brackets (with a French keyboard for instance brackets are not easy)
>> 2) when you have no brackets there are less risks to confuse, and wrongly add lines below action "thinking" they will be part of
>> the action
>>
>> Of course if the expression in action is long that's another story.
>> And then I still prefer to put brackets to be sure (but I'm a lot tempted to not put them ;o)
>>
>> Your opinions?
Re: Formatting question
Posted by Adam Heath <do...@brainfood.com>.
On 12/07/2012 06:08 AM, Jacques Le Roux wrote:
> Hi All,
>
> This is a personal question not specifically related to OFBiz nor any projects, just curious (and refreshing ;o)
>
> I'm seeking opinion about "one line" vs "multi lines w/t brackets" vs "multi lines w/out brackets" for "if" and "for" expressions
>
> I mean
>
> I personally prefer something like
>
> if (expres) action
When scanning code, 'sameness' goes into the background. If there are
differences, it stands out. Differences also make it harder to
process, as it takes the brain longer to realize it can skip it.
If some if-blocks have brackets, and some don't, then that is a
difference, and slows down understanding.
> than
>
> if (expres) {
> action
> }
My preferece.
>
> or
>
> if (expres)
> action
if (expres)
action
else
other-action
This is ugly. Adding additional actions inside the branch(s) is
confusing, without the {} already there.
>
> The reason is that IMO it prevents
> 1) to type useless brackets (with a French keyboard for instance brackets are not easy)
> 2) when you have no brackets there are less risks to confuse, and wrongly add lines below action "thinking" they will be part of the action
>
> Of course if the expression in action is long that's another story.
> And then I still prefer to put brackets to be sure (but I'm a lot tempted to not put them ;o)
>
> Your opinions?