[development] comment module: minor issue unreachable code

Earnie Boyd earnie at users.sourceforge.net
Wed Aug 22 13:01:09 UTC 2007



Quoting Gerhard Killesreiter <gerhard at killesreiter.de>:

>
> Also, putting a break even if it can't be reached is IMO good coding style.
>

Coding style is personal.  It is taught to us as we learn.  What may be 
good for one isn't necessarily good for another.  That is why we have a 
Coding Standard document.  But I haven't found this issue there.

<code style="Earnie">
switch ($myValue) {
  case (1): {
    ...
  } [break | return $case1Result];
  case (2): {
    ...
  } [break | return $case2Result];
  case (n): {
    ...
  } [break | return $casenResult];
  default: {
    ...
  } [break | return $defaultResult];
} <return $switchResult;>
</code>

As you can see I don't think break is always a good thing, it should 
either be return or break and return should not be embodied in the 
case.  Also I would never use break and return in the same switch; it 
should be one or the other and not both.  If break is used and a value 
needs returned from the switch/case operation then I put that on the 
line with the closing brace of the switch.

Earnie


More information about the development mailing list