Re: Setting flags versus checking for existing/nonexisting values

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

 



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

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