Re: Setting flags versus checking for existing/nonexisting values

From: Date: Tue, 15 Aug 2006 23:20:00 +0000
Subject: Re: Setting flags versus checking for existing/nonexisting values
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-240745@lists.php.net to get a copy of this message
On Tue, August 15, 2006 11:53 am, Chris W. Parker wrote:
Is it a better practice to set flags to determine the action of your code or is it perfectly acceptable to have your code determine what it should do based on the existence (or lack thereof) of data? For example:
-snip- flag example I seldom use flags, but then again I never use if/elseif's either. Flags introduce another variable you have to keep track of. When do you turn them on/off becomes another step in your logic that is directly dependant upon data in the first place. So, if logic dictates a branch, then I place the condition on the data. As I see it, in this case, only three conditions can exist: 1. Data is there, or not there -- use isset() or !isset(); 2. Data is relative to a single value -- use "if" with equalities (i.e., <=, ==,...); 3. Data is relative to two, or more, values -- use "switch". That works for me. But, I'm sure that mileage for others vary. tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#240745) next »