It's just pointless and possibly inefficient. If a var b is typed as Boolean, 
it is guaranteed to be either true or false, so you might as well just write

    if (b)

rather than

    if (b == true)

I haven't looked at the bytecode generated in the two cases, but I wouldn't be 
surprised if the latter case generated bytecode for the pointless comparison.

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Sam Lai
Sent: Saturday, February 07, 2009 6:21 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Making the impossible possible, something odd is 
happening


Curious question - why? Is there a technical reason for this, or just
a coding standard?

2009/2/8 Nate Beck <n...@tldstudio.com<mailto:nate%40tldstudio.com>>:
> I haven't had a change to play with your code... but just in general... It's
> bad practice to compare a Boolean value to True or False.
> You should simply be doing:
> if( x && y)
> instead of
> if (x == true && y == true)
> Cheers,
> Nate
>
> On Sat, Feb 7, 2009 at 5:04 PM, Cordova Aaron 
> <basic...@yahoo.com<mailto:basicasm%40yahoo.com>> wrote:
>>
>> I have an if else block that is matching every combination, all at once.
>>
>> To verify what I was suspecting I hard coded values to make portions of
>> the block impossible but they are still occuring, I'm assuming that the
>> project is not being rebuilt but when I comment lines, the code is no longer
>> executed, but the block is still executed.
>>
>> example
>>
>> x = true;
>> y = false;
>>
>> if(x == true && y == false)
>> {
>> doSomething();
>> }
>> else if(x== false && y == false)
>> {
>> if( x == true)
>> {
>> Alert.show("Should never happen.");
>> }
>> doSomethingElse();
>> }
>> else
>> {
>> //do nothing
>> }
>>
>> In my example I'm sure that I should never see the alert message, but I
>> get it the message every time the code is executed. I ran the 'Clean' option
>> in under the Build menu and the source recompiled, the problem remains.
>>
>
>
>
> --
>
> Cheers,
> Nate
> ----------------------------------------
> http://blog.natebeck.net
>
>
>
>
>

Reply via email to