On 7/02/2012, at 9:44 AM, Marco Behnke wrote:

> Am 06.02.12 17:23, schrieb Alain Williams:
>> However: a few GOTOs can make things clearer. Think of a function that
>> can fail in several different places (eg data validation, ...). But it
>> is reading a file which needs to be closed before the function
>> returns. I have seen code where some $IsError variable is tested in
>> many places to see if things should be done. That is just as bad as
>> lots of GOTO -- often when having to write something like that I will
>> have a GOTO (in 
> 
> Good code uses Exceptions and try catch for that kind of scenarios.

Exceptions have a lot of overhead and should only be used in exceptional 
circumstances. I don't see how data validation failing is an exceptional 
circumstance.

I find that using Exceptions and try/catch for something this trivial to be 
more confusing and harder to read (thus worse code) than a goto. It is also 
much easier to make a mistake, especially if you're expecting the catching to 
happen outside of the validation function.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to