terminate a PHP script - Page 4

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: terminate a PHP script

On 2/21/2011 9:04 PM, sheldonlg wrote:
Quoted text here. Click to load it

Forget it, Shelly - TNP can't tell the difference between a break (or an
if/then/else, for that matter) and a goto.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: terminate a PHP script

n00m wrote:
Quoted text here. Click to load it

Not me sir!

Thats a classic case for a goto!

Now consider 15 subroutines deep, and inside 10 for loops, and the
hardware says 'er, I lost connection to the other end'

And what you need to do is basically go to jail do not pass go, and
start over with a hardware rest/init sequence, and redo the whole thing
from start. THAT's yer longjmp(). Go to jail Do not pass Go. trash the
stack and start over.

Or consider how to write a multitasking interrupt driven scheduler in a
high level language.  Its awful. You need to  physically switch the
stack..to point to a stack whose location is stored  - gasp - in a
global variable!

Inside an asynchronous interrupt service routine.Yuk.

Re: terminate a PHP script

sheldonlg wrote:
Quoted text here. Click to load it
Because the nesting rapidly gets out of hand, and the 'what to do if its
NOT this' gets relegated to a bracket 5 pages further on completely
disconnected from the actual logical test that causes its invocation.


if (condition == what we want)

15 pages of code all nested
else // condition wasn't what we wanted in this instance
do some other crap
// now bugger off back to momma

is about as unreadable as it gets.

MUCH better is

    return(borked flavour one);
..15 pages of code with no nesting that takes it of the right hand side
of the screen, or paper.

reversing the condition logic to simply make the 15 pages an else clause
dosent get rid of the nesting.

When the aeroplane is on fire, you don't want to have to reverse your
way out of the cockpit drill and flight plan. You just want to hit the
eject button and abort the mission.

Re: terminate a PHP script

Tim Streater wrote:
Quoted text here. Click to load it
Pascal is unmitigated crap. Its a teaching language, not a language that
can be used to do anything useful. It enforces structure to the point
where you have to make a worse choice (the goto) than an early return..

Try creating a union in it as well..

PERSONALLY I find that early returns or breaks make for much easier to
follow code...that strict adherence to if then else..


function read_group()
while ($post)
    if ($poster=="stuckle")
        continue; //skip irrelevancies
    //now process data you are interested in...



reads much more eailyily than

function read_group()
while ($post)
    if ($poster!="stuckle")
        } //endif not stuckle


Because the latter, can lead to huge nesting and lots of else if else
type constructs.

It also follows the natural economy of thought that says

'if its him, don't even go there' which is the first thing you do.

THEN there may be other reasons to skip or abort. Get the exception
processing done early, simply and quickly, and then the real meat of the
processing is all in a simple block, rather than being interspersed with
exception processing.

That's the difference between academic purism and real life software
engineering: to the purist exception processing is something small that
should not sully the smooth flow of idealised control statements: To the
engineer exception processing is the biggest source of run time errors
and program bugs, and the more its all together and the easier it is to
understand and modify, the more robust the code is likely to be.

If that means saying, or the equivalent of saying

if(condition) go to errror1

if (condition) go to error2

and then collecting all the error handling code in one place, where it
can all be reviewed..sod the purists. I'll use goto, continue, return or
whatever the software allows, up to and including setjmp() and
longjmp()..which allowed me to write a piece of code that had functions
nested  so deep that the stack groaned under the strain, and instead of
having to check return values all the way up the return chain, I simply
discarded the whole stack, and ended up in a 'master reset with error
message'  part of the code..in a time period that was short enough to
keep the employer happy.

Probably the first rule of software engineering is that there is no rule
that cannot and occasionally should  be broken, and no rule that is
optimal in every case.

The goal is always clear comprehensible maintainable code that performs
the function for which it was designed: You have to ask yourself, punk,
whether use of a goto or equivalent, gets you nearer to, or further
from, that goal.

Exercises in egotistical cleverness and pedantry can, and should be,
left to usenet postings.

Site Timeline