|
With the likes of this[^] around, I'm surprised he remembers anything, the stuff can hurt you.
|
|
|
|
|
This^ is more to my liking.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
PIEBALDconsult wrote: Where were you during the days dazed?
FIFY: Correction should explain
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "As far as we know, our computer has never had an undetected error." - Weisert | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
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
|
|
|
|
|
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 { }
|
|
|
|
|
Marc Clifton wrote: You should be able to glean what the programmer intends to happen from the code.
Riiiiiiiiiiight!!!
|
|
|
|
|
Have you been to QA lately?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
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.
|
|
|
|
|
|
Exactly.
|
|
|
|
|
Yep, but this is a workaround, not a best practice though.
~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.
|
|
|
|
|
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
|
|
|
|
|
I thought that was the case - your response just seemed rather unNish-like .
Software Zen: delete this;
|
|
|
|
|
Heh
|
|
|
|
|
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 |.
|
|
|
|
|
|
>> 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 assume you meant it to do this:
bool more = ProcessFlyouts();
more = ProcessCarrierAnimations() || more;
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
|
|
|
|