05-06-2009, 02:28 PM
|
#14 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Wildhoney
In your example, you really don't need that else for the return because it's going to happen irrespective of anything else. In those examples where it either is or isn't, then check for an is, and the isn't will be the default.
Think of it in binary terms, yes/no, true/false, 0/1. If you check for the yes (true, 1), then the no (false, 0) is the resulting value, and can be returned as such.
It's when you introduce more complicated conditionals that it requires more thinking on your behalf, such as with hexadecimal (base-16), and even our base-10 counting system. Anything other than base-2 (binary), where we only have the possibility of 2 outcomes, which is fundamentally how computers work (and many more things, too), and so tends to be used quite commonly in everyday life, and to keep the topic relevant, in programming also.
I don't think there is any such performance gain, it's personal preference for readability, really.
|
Thanks, so this would work....
PHP Code:
function doThisAndThat($bTrueOrFalse)
{
if ($bTrueOrFalse) return 'It is true';
return 'It is false';
}
But I can see how that would look confusing so I wouldn't want to do it that way either....
I think for advanced programmers like yourselves, there becomes a thin line between preference and proper coding...although I tend to see more on the latter....
I've seen debates in the past on just where to place the brackets...
ex:
if() {
or
if()
{
Stuff like that when at the end of the day it's just preference...
|
|
|
|