return foo == null ? null : foo; return foo == null ? null : foo;Rather, it "evolves".
It starts as:
return foo == null ? error_handler(bar) : foo;
And someone realizes error_handler actually does nothing, so replaces all calls with null, mechanically.The same is probably true for this one here:
public bool ShowOptional() { bool bolReturn = false;
return bolReturn;
}There should be descriptions why the code snippets are supposed to be interesting, your and my example just look like legacy code to me.
Or maybe it's just stupid.
Sometimes you just can't tell the difference.
return !foo ? null : foo; return foo || null;
if you're into that sort of thing return foo == null ? true : false; return foo ? true : false;
or even return foo == true ? true : false;You are missing the point, which is it's really silly to transpose a boolean into a boolean using a ternary operator.
If you want to argue that "foo == null" is the problem due implicit nil value falseness, than the solution is simply to use strict comparison operator "===", transposing "foo == null" into a boolean doesn't solve the falseness issue if you think this is what the original author was trying to address.
"Hmmm, if 'foo == null' is true, than it's true... I see..."
Seriously..
function isAvailable(){ objInDb = findByName('Joan Carlos'); // the object or false
return objInDb ? true : false;
}But all this could be because I'm a noob in a language I don't really know... Php that magical land where nothing is what it looks like and is always ready to stab you in the back, can't say I'm a fan of it... Or dynamic languages, or anything magical... Ok, I'm going to places I don't want to remember, sorry...