Re: Setting flags versus checking for existing/nonexisting values

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

 





Chris W. Parker wrote:
Hello,

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:

<?php

if($value == 1)
{
	$flag = true;
}

if($flag === true)
{
	echo "I wish I could come to the PHP meetup in Chicago! :(";
}

?>

versus:

<?php

if($value == 1)
{
	echo "I wish I could come to the PHP meetup in Chicago! :(";
}

?>

Of course this is an overly simplistic example but you get the idea.

Are there pros and cons to both sides or should I just avoid the latter
example all together?



Thanks,
Chris.

Pros: potentially more readable code.
Cons: Wasted energy typing unnecessary lines of code.
Really I would say it comes down to coder preference.

(and why would you avoid the latter all together? Testing a boolean may be cleaner, but setting the boolean still relies on the value of $value, so if that value was fubar then the boolean would be too.)
-Brad

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