Re: Little question about switch CS

From: Date: Sat, 15 Jan 2005 19:29:38 +0000
Subject: Re: Little question about switch CS
References: 1 2 3 4 5  Groups: php.pear.qa 
Request: Send a blank email to pear-qa+get-2336@lists.php.net to get a copy of this message
Davey wrote:
FWIW, I think that the break should be in-line with the case, as in: switch (foo) {
    case 1:
        action1;
    break;
... }
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 >

« previous php.pear.qa (#2336) next »