Re: Coding style: `else for` or `else { for... }`?

2017-08-30 Thread Mike Hommey
On Wed, Aug 30, 2017 at 06:26:18PM -0600, Eric Rescorla wrote:
> On Wed, Aug 30, 2017 at 4:41 PM, Jeff Gilbert  wrote:
> 
> > IMO: Never else-for. (or else-while)
> >
> > Else-if is a reasonable continuation of concept: "Well it wasn't that,
> > what if it's this instead?"
> > Else-for is just shorthand for "well it wasn't that, so let's loop
> > over something".
> >
> > Else-if is generally used for chaining, often effectively as an
> > advanced switch/match statement.
> >
> > I've never actually seen else-for, but I imagine it would be used for:
> > if (!foo) {
> > } else for (i = 0; i < foo->bar; i++) {
> > }
> >
> > I don't think this pattern has enough value to be acceptable as
> > shorthand. BUT, I didn't know it was a thing until now, so I'm
> > naturally biased against it.
> >
> 
> I'm with Jeff here. Not even once.
> 
> if (!foo) {
> } else {
>   for(...) {
> 
> }
> }
> 
> As it happens, the style guide agrees with us, so I'm happy to quote it ;)
> 
> "else should only ever be followed by { or if; i.e., other control keywords
> are not allowed and should be placed inside braces."

... because it was added today after this thread:
https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style$compare?locale=en-US=1296847=1263305

Mike
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Coding style: `else for` or `else { for... }`?

2017-08-30 Thread Eric Rescorla
On Wed, Aug 30, 2017 at 4:41 PM, Jeff Gilbert  wrote:

> IMO: Never else-for. (or else-while)
>
> Else-if is a reasonable continuation of concept: "Well it wasn't that,
> what if it's this instead?"
> Else-for is just shorthand for "well it wasn't that, so let's loop
> over something".
>
> Else-if is generally used for chaining, often effectively as an
> advanced switch/match statement.
>
> I've never actually seen else-for, but I imagine it would be used for:
> if (!foo) {
> } else for (i = 0; i < foo->bar; i++) {
> }
>
> I don't think this pattern has enough value to be acceptable as
> shorthand. BUT, I didn't know it was a thing until now, so I'm
> naturally biased against it.
>

I'm with Jeff here. Not even once.

if (!foo) {
} else {
  for(...) {

}
}

As it happens, the style guide agrees with us, so I'm happy to quote it ;)

"else should only ever be followed by { or if; i.e., other control keywords
are not allowed and should be placed inside braces."

-Ekr





-Ekr


> On Wed, Aug 30, 2017 at 2:58 PM,   wrote:
> > Let's keep the flames alive!
> >
> > Should we always put braces after an `else`, with the only exception
> being another `if`?
> > Or should we also have exceptions for the other control structures
> (while, do, for, switch)?
> >
> > A.
> > if (...) {
> >   ...
> > } else {
> >   for (...) {
> > ...
> >   }
> > }
> >
> > B.
> > if (...) {
> >   ...
> > } else for (...) {
> >   ...
> > }
> >
> > I can see arguments for both, so I'm not too sure which one
> should win. :-)
> > WDYT?
> > ___
> > dev-platform mailing list
> > dev-platform@lists.mozilla.org
> > https://lists.mozilla.org/listinfo/dev-platform
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Coding style: `else for` or `else { for... }`?

2017-08-30 Thread gsquelart
Only negative reactions to `else for` so far, and it's only used a couple of 
times in our code:
http://searchfox.org/mozilla-central/search?q=else%5B+%5D%2B(do%7Cfor%7Cswitch%7Cwhile)%5B+%5D=true=true=*.cpp

So I'll add a clarification in the coding style page, that `else` should only 
be followed by `{` or `if`.

On Thursday, August 31, 2017 at 10:41:41 AM UTC+12, Jeff Gilbert wrote:
> IMO: Never else-for. (or else-while)
> 
> Else-if is a reasonable continuation of concept: "Well it wasn't that,
> what if it's this instead?"
> Else-for is just shorthand for "well it wasn't that, so let's loop
> over something".
> 
> Else-if is generally used for chaining, often effectively as an
> advanced switch/match statement.
> 
> I've never actually seen else-for, but I imagine it would be used for:
> if (!foo) {
> } else for (i = 0; i < foo->bar; i++) {
> }
> 
> I don't think this pattern has enough value to be acceptable as
> shorthand. BUT, I didn't know it was a thing until now, so I'm
> naturally biased against it.
> 
> On Wed, Aug 30, 2017 at 2:58 PM,  <gsque...@mozilla.com> wrote:
> > Let's keep the flames alive!
> >
> > Should we always put braces after an `else`, with the only exception being 
> > another `if`?
> > Or should we also have exceptions for the other control structures (while, 
> > do, for, switch)?
> >
> > A.
> > if (...) {
> >   ...
> > } else {
> >   for (...) {
> > ...
> >   }
> > }
> >
> > B.
> > if (...) {
> >   ...
> > } else for (...) {
> >   ...
> > }
> >
> > I can see arguments for both, so I'm not too sure which one should 
> > win. :-)
> > WDYT?
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Coding style: `else for` or `else { for... }`?

2017-08-30 Thread Jeff Gilbert
IMO: Never else-for. (or else-while)

Else-if is a reasonable continuation of concept: "Well it wasn't that,
what if it's this instead?"
Else-for is just shorthand for "well it wasn't that, so let's loop
over something".

Else-if is generally used for chaining, often effectively as an
advanced switch/match statement.

I've never actually seen else-for, but I imagine it would be used for:
if (!foo) {
} else for (i = 0; i < foo->bar; i++) {
}

I don't think this pattern has enough value to be acceptable as
shorthand. BUT, I didn't know it was a thing until now, so I'm
naturally biased against it.

On Wed, Aug 30, 2017 at 2:58 PM,   wrote:
> Let's keep the flames alive!
>
> Should we always put braces after an `else`, with the only exception being 
> another `if`?
> Or should we also have exceptions for the other control structures (while, 
> do, for, switch)?
>
> A.
> if (...) {
>   ...
> } else {
>   for (...) {
> ...
>   }
> }
>
> B.
> if (...) {
>   ...
> } else for (...) {
>   ...
> }
>
> I can see arguments for both, so I'm not too sure which one should 
> win. :-)
> WDYT?
> ___
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Coding style: `else for` or `else { for... }`?

2017-08-30 Thread gsquelart
Let's keep the flames alive!

Should we always put braces after an `else`, with the only exception being 
another `if`?
Or should we also have exceptions for the other control structures (while, do, 
for, switch)?

A.
if (...) {
  ...
} else {
  for (...) {
...
  }
}

B.
if (...) {
  ...
} else for (...) {
  ...
}

I can see arguments for both, so I'm not too sure which one should win. 
:-)
WDYT?
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform