Re: Long Live GOTO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06 Feb 2012 at 20:51, Simon J Welsh <simon@xxxxxxxxxxx> wrote: 

> 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.

While it is true that try/catch adds another level just like an extra if-then-else, there are times when it's unavoidable. During initialisation of my app, I have to check which of the files in a directory may be SQLite databases that belong to the app. So I have to check:

a) whether this file is an SQLite database
b) whether it has the two tables I expect to find there

Last time I checked the SQLite API in question, it looked as though try/catch was my only option.

--
Cheers  --  Tim

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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux