You'll get invited to our Meetups as soon as they're scheduled!
| From: | Dave Edelhart |
| Sent on: | Sunday, December 6, 2009 1:03 PM |
I regard the case structure as a kind of compact syntactic event handler; each case is a response triggered by the event it expects. however because of the "waterfall" behavior -- that is, the fact that you have the option of NOT including a "break" closure, you are NOT locked into the singular response that an (if/then/elseif)+ structure implies; that is one OR MORE events may fire off in response to the case key.
Here is the premise in spec form.
Are those two examples the same? Where is do_de_stuff() in the if/else? I think the switch should be easier to maintain when the application may add/delete cases, need a default, or change the procedures for any subset. The source code size is about the same, but I am not sure about the bytecode. Either way, the way to go is clearer to me when the $var values and their methods were semantically associated to the app.If you use if/else, this would be clearer to me --if ('a' == $var || 'b' == $var) {
do_b_stuff();
do_abc_stuff();
}elseif ($var == c) {
do_abc_stuff();
}elseif ('d' == $var) {
do_d_stuff();
do_de_stuff();
}
elseif ('e' == $var) {
do_de_stuff();
}else {do_exception();} // end pseudoswitch-------- Original Message --------
Subject: Re: [php-139] NEW TOPIC - PHP6
From: Joseph Engo <[address removed]>
Date: Tue, December 01, 2009 4:11 pm
To: [address removed]
This is a classic example of why I put the curly on the next line :P
On Dec 1, 2009, at 4:07 PM, Jesse Mullan wrote:
> Speaking of readability, that switch needs some comments.
>
> switch($var) {
> case 'a':
> /* Falls through */
> case 'b':
> do_b_stuff();
> /* Falls through */
> case 'c':
> do_abc_stuff();
> break;
> case 'd':
> do_d_stuff();
> /* Falls through */
> case 'e':
> do_de_stuff();
> break;
> }
>
>
> I dunno, which is more readable?
>
> if ('a' == $var || 'b' == $var || 'c' == $var) {
> if ('c' != $var) {
> do_b_stuff();
> }
> do_abc_stuff();
> } elseif ('d' == $var || 'e' == $var) {
> if ('d' == $var) {
> do_d_stuff();
> }
> do_e_stuff();
> }
>
>
> On Tue, Dec 1, 2009 at 3:04 PM, Dave Edelhart
> <[address removed]> wrote:
>
>> Cris does have a point in saying that there are readability issues
>> with the
>> switch Jesse posits. But you also cannot deny that the switch he
>> puts forth
>> does reflect a complex set of logical conditions in a very compact
>> unit of
>> code.
>> Readability is after all a reflection of what kind of code you
>> like/write/expect to be reading, and is therefore somewhat
>> subjective.
>
>
>
>
> --
> Please Note: If you hit "REPLY", your message will be sent to
> everyone on this mailing list ([address removed])
> /
> This message was sent by Jesse Mullan ([address removed]) from The
> San Francisco PHP Meetup Group.
> To learn more about Jesse Mullan, visit his/her member profile: /members/9265601/
> To unsubscribe or to update your mailing list settings, click here: http://www.meetup.com/account/comm/
> Meetup Inc. PO Box 4668 #37895 New York, New York 10163-4668 | [address removed]
>
--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
/
This message was sent by Joseph Engo ([address removed]) from The San Francisco PHP Meetup Group.
To learn more about Joseph Engo, visit his/her member profile: /members/8907494/
To unsubscribe or to update your mailing list settings, click here: http://www.meetup.com/account/comm/
Meetup Inc. PO Box 4668 #37895 New York, New York 10163-4668 | [address removed]
--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Michael ([address removed]) from The San Francisco PHP Meetup Group.
To learn more about Michael, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here
Meetup Inc. PO Box 4668 #37895 New York, New York 10163-4668 | [address removed]