Jeff Moore wrote:
function pseudocode() { try { $a = allocate_resource_z(); $b = allocate_resource_y(); $res = do_stuff(); $c = allocate_resource_x(); $res = do_more_stuff(); $d = allocate_resource_foo(); $res = do_even_more_stuff(); } catch ( Exception $e ) { free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); throw ($e); } }
Where did the if statements go? do_stuff(), do_more_stuff(), and do_even_more_stuff() should throw exceptions rather than return boolean error indicators.
True, which is really just a more revised version of the point that's been being passed around in one form or another. I was assuming the functions called didn't necessarily throw errors, like a PHP internal or similar, where you'd want to check the return code - but for an application coded around try/catch/throw, this would work perfectly.
Personally, I'm used to the PEAR_Error, and PEAR::isError() method of error handling, so having the luxury of try/catch/throw in PHP 5 is a major improvement. But I guess the point is that having goto isn't really essential, as the original example tried to imply.
But Ilia and Rasmus are also correct in that it wouldn't really hurt anything to add goto functionality, either. Most would ignore it, and it can only scope locally, so there's little chance of spaghetti. Sure, it's gross in general, but PHP isn't Python: enforcing coding style isn't PHP's thing.
And as others have pointed out, we can all cite code that looks nasty, regardless of the presence of goto. For anyone who's ever seen Python code that *only* follows the indentation requirement, it does little to improve overall quality of the end product. Bad programmers will always find ways around language constructs, intentionally or otherwise. I'm just waiting for a language that imposes Javadoc style commenting in a 40% or greater ratio of comments to code, consistent indentation, brace style, and so on, just to see how it gets circumvented. Which is why I find it amusing PHP enforces camel-caps for class method names; that simply encourages bad programmers to use all lower case to avoid the issue entirely.
-- Shaun M. Thomas INN Database Administrator Phone: (309) 743-0812 Fax : (309) 743-0830 Email: [EMAIL PROTECTED] Web : www.townnews.com
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php