Re: switch case - to require the break statements seems strange to me
| From: | Andrew Ballard | Date: | Fri, 12 Sep 2008 15:39:43 +0000 |
| Subject: | Re: switch case - to require the break statements seems strange to me | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280010@lists.php.net to get a copy of this message | ||
On Fri, Sep 12, 2008 at 9:52 AM, Jochem Maas <jochem@iamjochem.com> wrote:
> Luke schreef:
>>
>> I wonder if this is a shared trait between C and PHP (since I understand
>> PHP
>> is written in C) that the break; and the default: are placed for good
>> practice in all switch statements since they prevent memory leaks?
>
> default is not required, never heard it was good practice to always put it
> in.
I can't say I've ever heard it recommended as good practice from the
standpoint of performance in any specific language I've ever worked
with, but I have heard people suggest that you always include an
explicit default case in any kind of branching logic. It does seem
useless to say
default: // do nothing
break;
in a switch block, but I imagine the reasoning behind it is so that
anyone who reads your code can see that you actually thought about
what should/would happen if none of the other conditions were true
rather than ignoring those conditions.
Andrew