|
Posted by Tim Martin on 04/24/06 16:02
Steve wrote:
> On Fri, 21 Apr 2006 11:20:27 +0100, Tim Martin wrote:
>> Sorry, I misread you. I thought you were referring to replacing the
>> second '&', not the first one. I didn't even spot that the two boolean
>> expressions were being combined with a bitwise operator (which I agree
>> is wrong).
>>
>> For reference, the function in question was:
>>
>> function is_even($num){
>> return (is_numeric($num)&(!($num&1)));
>> }
>
> Why is it wrong? you're anding 0 or 1 with 0 or 1, and that'll return 1
> only if both are 1. It might even be faster - probably not though.
It's wrong in the sense of being a bad habit, not in the sense of
returning the wrong result. Doing this sort of thing regularly can lead
to brittle code that breaks due to seemingly innocuous changes.
Tim
Navigation:
[Reply to this message]
|