PQOTD
-
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".
-
I do not like that change from C/C++...I mean the | and || changes... X|
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
>> I do not like that change from C/C++...I mean the | and || changes... Exactly, what changes are those? I've used C# for 10 ten years, and C/C++ for the ten years before that, and have noticed no differences in the handling of logical operators.
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
My bet is that ProcessCarrierAnimations isn't executed if ProcessFlyouts returns true. If ProcessCarrierAnimations should still be called, you could remove one of the "vertical bars", changing the "short-circuit" OR into a regular logical-OR. Richard
-
You should be able to glean what the programmer intends to happen from the code. :) Marc
Without further information, it is obvious that the programmer intended ProcessCarrierAnimations() to only be called if ProcessFlyouts() returns false. I'm with OriginalGriff on this..
ProcessCarrierAnimations() || more;
This is clearly the better way to express intent that using a bitwise OR. Unless there are tests like this all over the code done with bitwise ORs, using one here requires the next programmer to notice you did something atypical here in a fairly subtle way, which means its a maintenance hazard, which in my book is part of the definition of poor coding.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
-
My bet is that ProcessCarrierAnimations isn't executed if ProcessFlyouts returns true. If ProcessCarrierAnimations should still be called, you could remove one of the "vertical bars", changing the "short-circuit" OR into a regular logical-OR. Richard
hhhmmm...I never thought of bitwise operators as being the 'regular' ones; quite the contrary, actually.
-
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 failed to run ProcessCarrierAnimations because more was already true, and thus the evaluator short-circuited. You want something like this:
bool more=ProcessFlyouts();
bool more2=ProcessCarrierAnimations();
more = more || more2; -
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
if(!ProcessFlyouts()) { ProcessCarrierAnimations() }