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
-
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
-
Can you define 'right'?
[Flags]
public enum Bool {
True, False, ForSure, Maybe, ProbablyNot, Depends, NotDecidedYet, Undefined
}private interface IStealth { }
You should be able to glean what the programmer intends to happen from the code. :) 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
|
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
-
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
I'm not quite sure what was unexpected here. If you mean the ProcessCarrierAnimations() never gets called if (more == true) then it really was expected :) However changing || to | will make it called regardless of more's value.
-- "My software never has bugs. It just develops random features."
-
You should be able to glean what the programmer intends to happen from the code. :) Marc
Maybe, if I could see the content of both methods that return a bool :) Otherwise, quite hard to detect a logic issue when the logic itself is not told.
[Flags]
public enum Bool {
True, False, ForSure, Maybe, ProbablyNot, Depends, NotDecidedYet, Undefined
}private interface IStealth { }
-
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
I assume you meant it to do this:
bool more = ProcessFlyouts();
more = ProcessCarrierAnimations() || more;:laugh: Would do the same in C and C++ as well.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
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
I assume that you want to run the second method if first returns true, if that the case you have to switch the order
bool more = ProcessFlyouts();
more = ProcessCarrierAnimations() || more;I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
-
|
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
Exactly. :)
-
I'm not quite sure what was unexpected here. If you mean the ProcessCarrierAnimations() never gets called if (more == true) then it really was expected :) However changing || to | will make it called regardless of more's value.
-- "My software never has bugs. It just develops random features."
deflinek wrote:
However changing || to | will make it called regardless of more's value.
Yup! Marc
-
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 |.
Yup. | Marc
-
I assume you meant it to do this:
bool more = ProcessFlyouts();
more = ProcessCarrierAnimations() || more;:laugh: Would do the same in C and C++ as well.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
OriginalGriff wrote:
more = ProcessCarrierAnimations() || more;
Quite so. The bitwise | operator solves the problem too. Marc
-
I assume that you want to run the second method if first returns true, if that the case you have to switch the order
bool more = ProcessFlyouts();
more = ProcessCarrierAnimations() || more;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:
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
The right hand operand of a || shall not contain side effects
The operands of a logical || shall be primary expressionsThe example you gave is the very reason for the above two rules.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus Entropy isn't what it used to.
-
OriginalGriff wrote:
more = ProcessCarrierAnimations() || more;
Quite so. The bitwise | operator solves the problem too. Marc
Yes - but I don't like bitwise operators with bools...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
|
Regards, Nish
Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview
-
Kornfeld Eliyahu Peter wrote:
you have to switch the order
Yes indeed. Or use the bitwise operator. Marc
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)
-
The right hand operand of a || shall not contain side effects
The operands of a logical || shall be primary expressionsThe example you gave is the very reason for the above two rules.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus Entropy isn't what it used to.
-
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
Though Nish's and OG's examples will work, I think it is symantically better to do this:
bool more = ProcessFlyouts();
bool foo = ProcessCarrierAnimations();
more = more || foo;Less terse code (normally bad) - but explicit in calling
ProcessCarrierAnimations
.PB 369,783 wrote:
I just find him very unlikeable, and I think the way he looks like a prettier version of his Mum is very disturbing.[^]