Re: Re: Long Live GOTO

From: Date: Mon, 06 Feb 2012 20:51:50 +0000
Subject: Re: Re: Long Live GOTO
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-316495@lists.php.net to get a copy of this message
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/

« previous php.general (#316495) next »