PQOTD
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
How about:
more &= ProcessCarrierAnimations();
The difficult we do right away... ...the impossible takes slightly longer.
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
Is it just me that would have done it as a oneliner?
Wrong is evil and must be defeated. - Jeff Ello[^]
-
Is it just me that would have done it as a oneliner?
Wrong is evil and must be defeated. - Jeff Ello[^]
That could make setting a breakpoint on the second call difficult. :shrug:
You'll never get very far if all you do is follow instructions.
-
That could make setting a breakpoint on the second call difficult. :shrug:
You'll never get very far if all you do is follow instructions.
No big deal to change if necessary. :shrug: But I actually find it easier to read on one line.
Wrong is evil and must be defeated. - Jeff Ello[^]
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
-|
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost "All users always want Excel" --Ennis Lynch
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
There's a risk that
ProcessCarrierAnimations()
may never be invoked, so the right thing (IMHO) would be to do something like this:bool processFlyouts = ProcessFlyouts();
bool processCarrierAnimations = ProcessCarrierAnimations();
bool more = processFlyouts || processCarrierAnimations;/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
Kornfeld Eliyahu Peter wrote:
you have to switch the order
Yes indeed. Or use the bitwise operator. Marc
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
-
Yeah! It compiles. After then you can rub your head to find where the bug is!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
Kornfeld Eliyahu Peter wrote:
It compiles. After then you someone else will can rub your their head to find where the bug is!
FTFY :-D
The report of my death was an exaggeration - Mark Twain
Simply Elegant Designs JimmyRopes Designs
I'm on-line therefore I am. JimmyRopes -
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
It compiled?
========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================
-
I never follow other peoples' rules. :cool:
You'll never get very far if all you do is follow instructions.
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
Just to be contrary:
bool more = false;
if (ProcessFlyouts()) more = true;
if (ProcessCarrierAnimations()) more = true;Software Zen:
delete this;
-
|
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
Yuck. One of my least favorite things when reading someone else's C/C++ code is when they mix logical and bit-wise operators in an expression. In this case, using a bit-wise operator on
bool
values just seems wrong.Software Zen:
delete this;
-
Yuck. One of my least favorite things when reading someone else's C/C++ code is when they mix logical and bit-wise operators in an expression. In this case, using a bit-wise operator on
bool
values just seems wrong.Software Zen:
delete this;
I agree, it's not something I'd use myself. I was only answering Marc's academic question :-)
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
-
I agree, it's not something I'd use myself. I was only answering Marc's academic question :-)
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
I thought that was the case - your response just seemed rather unNish-like :laugh:.
Software Zen:
delete this;
-
I thought that was the case - your response just seemed rather unNish-like :laugh:.
Software Zen:
delete this;
Heh :-)
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
-
It will run either ProcessFlyouts, or ProcessCarrierAnimations, or neither, and the variable will tell you if it successfully ran either. I would imagine you either want && or |.
>> It will run either ProcessFlyouts, or ProcessCarrierAnimations, or neither, Um... Not even close. It will, unquestionably, run ProcessFlyouts. It may also run ProcessCarrierAnimations.
Truth, James
-
Programming Quiz of the day. I just wrote this code (C#), which did something very unexpected. What was it that it unexpectedly did?
bool more = ProcessFlyouts(); more = more || ProcessCarrierAnimations();
How would you change it to "do the right thing?" Marc
The "early out" semantics of the logical operators (|| and &&) are the same for C#, C++, Java, and C, and have been well-specified since the First Edition of K&R C. How could the result possibly be unexpected?
Truth, James
-
>> It will run either ProcessFlyouts, or ProcessCarrierAnimations, or neither, Um... Not even close. It will, unquestionably, run ProcessFlyouts. It may also run ProcessCarrierAnimations.
Truth, James
That is pretty close to what I said, although that was admittedly technically wrong. (I understand how || works but apparently failed in the challenge of writing English!) "Not even close" would be "it returns banana or grapefruit depending on the wolf".