FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » terminate a PHP script
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: terminate a PHP script [message #172643 is a reply to message #172629] Wed, 23 February 2011 08:19 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
Tim Streater wrote:
> In article <ijv2mp$3tc$2(at)news(dot)albasani(dot)net>,
> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>
>> Peter H. Coffin wrote:
>>> On Mon, 21 Feb 2011 18:50:39 +0000, Tim Streater wrote:
>>>> Because of the incredible convolution and depth of nested
>> if/then/else >> you can get to. If I have (as it might be) a function
>> that's scanning a >> string looking for and obtaining options and
>> their values for some >> command previously scanned off the string,
>> and I detect an error, I want >> to set an error code and exit right
>> there. I don't want any subsequent >> maintainer to have to intuit
>> that, in fact, from this point on nested >> 15-deep in else clauses,
>> no more code is executed for that path through >> the function.
>>>>
>>>> That way I rarely get more than 3-deep in if/then/else. To me, it's
>> all >> about readbility.
>>>> *grin* for me, it's all about comprehesibility. If you don't like how
>>> deep you're nesting, maybe you need to break something out into a
>>> function instead....
>>> Yes, but how much stack do you have? Can you afford the overhead of
>> a call/return?
>
> Shitloads, and yes.
>
>> How much does splitting a whole block of code to four pages away make
>> the comprehensibility problem worse, not better?
>
> Not at all, if you think about what you're doing. Here is an actual
> piece of code from my application (OK, it's JavaScript and not PHP, but
> the idea's the same):
>
> switch (subItems[0])
> {
>
> case "C":
> composeMail (subItems[1], tabstr);
> break;
>
> case "L":
> writeLogmsg (subItems[1]);
> break;
>
> case "N":
> addNewMail (subItems[1]);
> break;
>
> case "R":
> replaceMail (subItems[1]);
> break;
>
> case "T":
> tabstr = subItems[1];
> break;
>
> case "X":
> writeLog ("RC", "failed to generate reply mail");
> break;
>
> case "Z":
> break;
>
> default:
> alert ("replyContinue: " + subItems);
> return;
>
> }
>
> Each of the functions referred to has a well-defined purpose - and in
> some instances is called from more than one place. But even if there was
> just the one place where a call is made, I'd still be likely to do it
> this way.
>

Yes, and I usually do it that way as well.

But not always and not slavishly.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Extralight browser-webserver communication via cookies (+)
Next Topic: Storing multiple character set types (or a representation of em) in a table column
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 01:57:23 GMT 2024

Total time taken to generate the page: 0.04519 seconds