Re: GOTO operator
| From: | Michael Walter | Date: | Sun, 01 Aug 2004 03:50:05 +0000 |
| Subject: | Re: GOTO operator | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-11783@lists.php.net to get a copy of this message | ||
Andi Gutmans wrote:
I'm starting to like goto more and more :) Good good :)
At least it's a simple concept as opposed to using/scoped which make me dizzy. Hehe, I think scoped could be pretty useful, though.Cheers, Michael
At 03:24 AM 8/1/2004 +0200, Michael Walter wrote:Paul G wrote:what you are suggesting----- Original Message ----- From: "Michael Walter" <cm@leetspeak.org> To: "Paul G" <paul@rusko.us>; <internals@lists.php.net> Sent: Saturday, July 31, 2004 1:59 PM Subject: Re: [PHP-DEV] GOTO operator --- snip ---Of course, what makes you think C#'s using() is restricted to deallocation?free()presumably, you see the need in C because it's the cleanest way toout.all you've malloc()ed along the way, regardless of where you've erroredobjects,in PHP, you've got gc, which (again presumably) makes you think we don't need goto. i say that we alloc() stuff quite often, but it may beactually, alloc/dealloc was just used as an example. it could be anything - rollback, closing sockets, pretty much any sort of 'undoing' that you need to do to make it look like nothing ever happened ;)resources, what have you instead of chunks.It's interesting that there is the desire for a low-level construct such as "goto" in order to implement scoped deallocation/deconstruction. I suppose something like C#' using() statement might help you in this case, although suggesting it will surely lead to another discussion ;)is similar to the hack i'm using now and referred to in an earlier mail, ie registering thingers to be 'undone'. while useful for certain things, it's too verbose for the majority of situations When Done Here(tm).Actually what I was throwing into the discussion is IMO often the cleaner solution. You encapsulate _both_ construction and destruction logic into the same object, and as a client you just use the using() statement in order to have the language take care about the management. Another possibility, possibly more concise, would be to introduce a "scoped" keyword (or similar) in the spirit of "global": scoped $foo; might make $foo's destructor be called at the end of the current scope (whether left by a return statement or by an exception). Note that this only solves one part of the problem which could be summarized as "resource management". I'm not sure about generated code - did someone already post an example where goto might be useful in that case or did I miss that one? Cheers, Michaelpaul paul-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php