|
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
The report of my death was an exaggeration - Mark Twain
Simply Elegant Designs JimmyRopes Designs
I'm on-line therefore I am.
JimmyRopes
|
|
|
|
|
>> 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
|
|
|
|
|
Marc Clifton wrote: bitwise operator
So boolean is foolish?
|
|
|
|
|
MISRA[^] Rule 33 & 34:
The right hand operand of a || shall not contain side effects
The operands of a logical || shall be primary expressions
The 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.
|
|
|
|
|
There's actually some nice concise uses of
var result = DoSomething() && DoSomethingThatDependsOnIt();
var result = DoSomething() || HandleFailureCase();
It's even better in languages where you can use non-boolean types with the boolean operators.
|
|
|
|
|
Let's say I have never seen these two lines of code, OK ?
~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.
|
|
|
|
|
Ouch! && Ouch! || Ouch!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I never follow other peoples' rules.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
It's my rule that people have to breathe (or die trying).
|
|
|
|
|
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 .
|
|
|
|
|
"Eliminate needless local variables."
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
more |= ProcessCarrierAnimations(); ?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
var more = more || initalizeMore();
is a common practice in javascript.
|
|
|
|
|
Now, I'm not going to look at the other answers before I post so I don't know if others have got it right, or if there are additional nuggets of information. If ProcessFlyouts returns true then the second test isn't carried out - it's a conditional OR statement. So, if you want ProcessCarrierAnimations to be evaluated, convert it to
more = more | ProcessCarrierAnimations();
|
|
|
|
|
How about:
more &= ProcessCarrierAnimations();
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Is it just me that would have done it as a oneliner?
|
|
|
|
|
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.
|
|
|
|
|
|
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
|
|
|
|
|
No it did not do anything unexpected. || operator uses short-circuit evaluation. I would assume the intent was to call ProcessCarrierAnimations only if more was false.
|
|
|
|
|
It compiled?
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
This is JavaScript style, the developer meant, if "more" is "undefined" then try the other option ProcessCarrierAnimations(). But obviously, this doesn't work in C#.
Make it simple, as simple as possible, but not simpler.
|
|
|
|
|
Just to be contrary:
bool more = false;
if (ProcessFlyouts()) more = true;
if (ProcessCarrierAnimations()) more = true;
Software Zen: delete this;
|
|
|
|