For Programmers: Free Programming Magazines  


Home > Archive > PHP PEAR Questions and Answers > January 2005 > Re: [PEAR-QA] Little question about switch CS









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR-QA] Little question about switch CS
Helgi Žormar

2005-01-13, 3:58 pm

On Thu, 2005-01-13 at 12:18, Helgi =DEormar wrote:
> Hi guys,
>=20
> http://pear.php.net/manual/en/standards.control.php anyone, am I the
> only one that things placing a extra new line after breaks is just quite
> unnecessary ?
>=20
> I think most of the devs only use 1x new line, it's the most cleanest
> IMHO, at least I think we should allow people to choose between 1 or 2x,
> because if the switch sentence is a small one then it's okey to have 1x
> new line, but if people are stuffing a lot of stuff in each case then it
> makes sense to use 2x new lines.
>=20
> So is anyone against changing this ? What I'm proposing will keep BC
> (even tho those things are less of a issue in regards to CS ;)).
>=20
> - Helgi


Also brought to my attention (I just didn't notice this my self ;D
*feels silly*) is that the manual doesn't indent, I feel that it should
be like this:

//short switches
switch (condition) {
case 1:
action1;
break;
case 2:
action2;
break;
default:
defaultaction;
break;
}

// long switches
switch (condition) {
case 1:
action1;
break;

case 2:
action2;
break;

default:
defaultaction;
break;
}

I usually align the breaks with content but this makes much more sense.

Anyway what do you guys think about those changes ?

- Helgi
Daniel Convissor

2005-01-14, 3:57 am

On Thu, Jan 13, 2005 at 05:19:54PM +0000, Helgi ?ormar wrote:

The switch statement section is definitely the most common "let's revise
the standard" thread. There was one back in early '04, if I remember
correctly.

I prefer the following for both short and long:

switch (condition) {
case 1:
action1;
break;

case 2:
action2;
break;

default:
defaultaction;
}

Similar to the existing standard, but with the cases indented, just like
every other bracketed thing in the standard.

Thanks,

--Dan

--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
Alan Knowles

2005-01-14, 3:57 am

Daniel Convissor wrote:

>On Thu, Jan 13, 2005 at 05:19:54PM +0000, Helgi ?ormar wrote:
>
>The switch statement section is definitely the most common "let's revise
>the standard" thread. There was one back in early '04, if I remember
>correctly.
>
>

Yeah - I brought it up, I think after someone asked me about it.. - more
in relation to the fact that I've been the indentation illustrated
below, and not what was in the manual. I think the conclusion was
something along the lines, of not to change it, but to ignore the fact
that people where adding the extra indentation. (From what I remember it
was regarded as a little petty to enforce such a major change either way. )

I cant remember if this was in the context of having a few 'recommended,
but not essential elements to the CS section'.
Regards
Alan



>I prefer the following for both short and long:
>
> switch (condition) {
> case 1:
> action1;
> break;
>
> case 2:
> action2;
> break;
>
> default:
> defaultaction;
> }
>
>Similar to the existing standard, but with the cases indented, just like
>every other bracketed thing in the standard.
>
>Thanks,
>
>--Dan
>
>
>

Sean Coates

2005-01-14, 3:57 pm

Daniel Convissor wrote:
> On Thu, Jan 13, 2005 at 05:19:54PM +0000, Helgi ?ormar wrote:
>
> The switch statement section is definitely the most common "let's revise
> the standard" thread. There was one back in early '04, if I remember
> correctly.
>
> I prefer the following for both short and long:


FWIW, I think that the break should be in-line with the case, as in:

switch (foo) {
case 1:
action1;
break;
....
}

Why? For exactly the same reasons we do this:
if (foo == 1) {
action1;
}

and not:
if (foo == 1) {
action1;
}

(easier to see where a block begins and ends)

S
Mika Tuupola

2005-01-14, 3:57 pm

On Thu, 13 Jan 2005, Daniel Convissor wrote:

> I prefer the following for both short and long:
>
> switch (condition) {
> case 1:
> action1;
> break;
>
> case 2:
> action2;
> break;
>
> default:
> defaultaction;
> }


I prefer this too. Although I tend to like to have the
break after default too for the reasons Patrin explained
in his mail.

--
Mika Tuupola http://www.appelsiini.net/~tuupola/
Klaus Guenther

2005-01-14, 3:57 pm

Daniel Convissor wrote:
> On Thu, Jan 13, 2005 at 05:19:54PM +0000, Helgi ?ormar wrote:
>
> The switch statement section is definitely the most common "let's revise
> the standard" thread. There was one back in early '04, if I remember
> correctly.
>
> I prefer the following for both short and long:
>
> switch (condition) {
> case 1:
> action1;
> break;
>
> case 2:
> action2;
> break;
>
> default:
> defaultaction;
> }
>
> Similar to the existing standard, but with the cases indented, just like
> every other bracketed thing in the standard.


+1 here, too... but for some reason, CS is a holy cow and any time you
touch it, everyone starts clamoring for other changes. If CS is decreed
from on high, that's not a problem. But if you have to run an RFC
through, after the first RFC, everyone and their brother will submit an
RFC and I'm not too thrilled by that prospect. IMHO, we need The PEAR
Group to make a decision regarding changing CS. I'd be happy if it would
be a joint effort between The Group and the QA Core Team (with joint
voting) rather than throwing it open to pear-dev. And no, I'm against
frivolous changes. If it doesn't make the code cleaner, reading it
easier or the code run faster, let's forget about it.

Klaus
Davey

2005-01-15, 3:56 pm

Sean Coates wrote:
> Daniel Convissor wrote:
>
>
>
> FWIW, I think that the break should be in-line with the case, as in:
>
> switch (foo) {
> case 1:
> action1;
> break;
> ...
> }


<snip>

Personally, I find that the next "case *:" tells me where
the previous block ended or the closing brace.

I prefer

switch (foo) {
case 1:
action1;
break;
case 2:
action2;
break;
}

This means its easier to see the list of case conditions, and I don't
need to mentally block out the "break;"'s

Still, its very trivial, I think we shouldn't force the user either way
on this point, except to that it should be one or the other.

- Davey
bertrand Gugger

2005-01-16, 3:56 am

Davey wrote:

>
> Personally, I find that the next "case *:" tells me where
> the previous block ended or the closing brace.
>
> I prefer
>
> switch (foo) {
> case 1:
> action1;
> break;
> case 2:
> action2;
> break;
> }
>
> This means its easier to see the list of case conditions, and I don't
> need to mentally block out the "break;"'s


Are you mentally blocking out the close bracket the same ?
Obviously a "case" introduce a new level in sequence same as "if ... {"
(seems everybody agree on that)
Similary a "break" introduce a back level as "}"so according to pear's
CS should unindent first,
and not get some double back indentation as after "break" in your example.
Sean's one there above is consequent with this rule.

>
> Still, its very trivial, I think we shouldn't force the user either
> way on this point, except to that it should be one or the other.


Interpreters and tokenizers don't mind that ;)
What do you think of this one ?
Once upon a time, I was writing:

switch (foo) {
case -1:
action-1;
break; case 0: case 1:
action01;
break; case 2:
action2;
break; otherwise:
even if no action otherwise (it 's an old remiscence, is that
Pascal ? ;)
}
It's awfull, but convenient.
and schematic the same as "} else {"

I hope it was understable.
+1 for Sean's
--
bertrand Gugger (toggg)

>
> - Davey
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com