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 #172641 is a reply to message #172624] Wed, 23 February 2011 08:15 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
sheldonlg wrote:
> On 2/21/2011 10:38 PM, The Natural Philosopher wrote:
>> Exactly.
>> some form of limited goto is always required: teh questin is how to
>> wrire it best. After all consider thus staement
>>
>> if ()
>> {
>> }
>> else...
>> {
>> }
>> what is the else, but a target for a conditional jump? Just because you
>> didn't write goto, doesn't mean there aint no jump.
>
> No argument with that part. However, when I first saw if-then-else my
> reaction was "Wow! That is exactly how people think. No need to do
> convoluted logic with going to different labels in one case or the other
> and remembering where and how I got there and what to do next."
>
> What is done behind the scenes to implement that logic? Why jumps, of
> course, to labels created by the compiler/interpreter. So what? Why
> should I care? The point was to have READABLE and MAINTAINABLE code.
> Since if-then-else is how people think, it is far, far, far more
> readable and maintainable than jumps. That is implemented behind the
> scenes that way? So what?

I think that is ultimately the whole point.

The language is a mapping between human logic and the actual hardwired
logic of the processor.

If you DO think like 'if then else', that's a good mapping.

But if your way of expressing the action required is 'if you land here,
go directly to gaol. do not pass GO, do not collect £200' then what I am
saying is that a construction that reflects that is sometimes easier.

It doesn't have to be a goto, as we have seen, a break, return, continue
or even a brace, represents the same thing in a more retysricted way.


>
> As for labels being confined to the scope of the function, again so
> what? Jumping off a six story building will kill you just as surely as
> jumping off the Empire State Building. Your blood might spatter a
> little less, but you will still be dead.
>
By definition a function is less than the whole code, so at least you
don't have to scan the whole code looking for the target.


In the end that's what this is all about: how far you have to search the
source code for that label, curly brace or whatever, to find out where
that condition takes you.

A six page if statement which then turns out to have no else is merely a
lot of nesting you can get rid of by a simple 'if not, then return;',
for example.

Likewise the solution of putting everything in nested functions, is no
solution when you are so deeply nested that an error at the bottom
level that needs to be a complete abort of all the calling functions as
well, means you have to add error processing all the way up the chain so
the original function knows that something has gone wrong in the Mariana
trench, and deal with it.

In such case a construction that can cut across and bypass all the
normal program flow is useful.

That's the setjmp/longjmp.

Of course you need to be careful. Any local stack variables will be
automatically cleaned up, but if you have .. used malloc() all bets are
off as to whether stuff will be 'free()ed.

And local static variables will remain where you left them, of course.
So you had better initialise them before you use them again.


Its a nasty piece of code to write whichever way you tackle it, but all
I am saying is that when you occasionally have to, it's better to have a
full toolbox, than one that is deliberately restricted because someone
somewhere took a purist attitude to the basic consideration of program
flow. He doesn't have to solve this problem: You do.


Lets face it, even a modern WinPeeCee has a key sequence that is thge
ultimate incarnation is 'please jump to reset, and sod everything else'

Ctrl-Alt-Del..

When I was(briefly) involved with military stuff, the practice was to
fill the ROM code with blocks of JMP RESET code in between actual
functions and statements, on the basis that of a strong EMP came along
and knocked the program stack and data registers and RAM to kingdom
come, you had some chance of being able to restart the machine. That
could also be invoked by the failure of a watchdog timer, to be reset,
which it would be if normal program flow was operational.. you really
don't want a missile flying around with its software in an indeterminate
state..

Really GOTOS are deprecated because they allow you to create
unmaintainable code too easily. They also can allow you to create MORE
maintainable code. The problem is not on the construct itself, its in
its deployment.

You don't use a chainsaw to prune. But its a useful thing to remove a
whole tree.
[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: Fri Jul 05 18:17:12 GMT 2024

Total time taken to generate the page: 0.04519 seconds