Prev: Displaying property menu at runtime
Next: Delay Methods
From: Kevin Provance on 19 Jul 2010 21:28 Hey C++ guys, what is the advantage or purpose of this? If (FALSE == SomeFunction()) { .... } Why put FALSE == instead of the function first, like we usually do? -- Customer Hatred Knows No Bounds at MSFT Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc Bawwk! Paulie want a dingleball, bawwk!
From: dpb on 19 Jul 2010 21:34 Kevin Provance wrote: > Hey C++ guys, what is the advantage or purpose of this? > > If (FALSE == SomeFunction()) > { > ... > } > > Why put FALSE == instead of the function first, like we usually do? It's defensive coding style advocated by some--if accidently write w/ only one "=" the non-assignable lhs will trigger compilation error. AFAIK that's the only purpose (but I'm no C/C++ guru, I've just seen it as one of the suggestions in Dan Saks columns amongst other places iirc). --
From: Karl E. Peterson on 19 Jul 2010 21:48 Kevin Provance submitted this idea : > Hey C++ guys, what is the advantage or purpose of this? > > If (FALSE == SomeFunction()) > { > ... > } > > Why put FALSE == instead of the function first, like we usually do? I've done that, occassionally, because so often you're testing for Not False, and just omit the test altogether. And, if it's a really long function call, the test may hang off the end of the window. So, to me, these are the typical choices: If SomeFunction() Then or: If SomeFunction() = False Then But what if the function has eight or nine parameters, and you end up with: If SomeFunction(Byval aLongVarName, ByVal SomeMoreData, ByVal Blah, By<clipped> Are you testing for true or false? If you put the False up front, it's really clear when you make an exception to the normal situation. -- ..NET: It's About Trust! http://vfred.mvps.org
From: Kevin Provance on 19 Jul 2010 22:42 "Karl E. Peterson" <karl(a)exmvps.org> wrote in message news:i22va8$qjs$1(a)news.eternal-september.org... : : Are you testing for true or false? If you put the False up front, it's : really clear when you make an exception to the normal situation. I'm converting some C++ code to VB (specifically dealing with CAB files) and I noticed the call was...reversed. I was just curious if there was a specific reason why. Tis all. :-)
From: Cor on 20 Jul 2010 04:48
It shows direct the knowledge of the developer. "Kevin Provance" <k(a)p.c> wrote in message news:i22u46$i8d$1(a)news.eternal-september.org... > Hey C++ guys, what is the advantage or purpose of this? > > If (FALSE == SomeFunction()) > { > ... > } > > Why put FALSE == instead of the function first, like we usually do? > > -- > Customer Hatred Knows No Bounds at MSFT > Free usenet access at http://www.eternal-september.org > ClassicVB Users Regroup! comp.lang.basic.visual.misc > > Bawwk! Paulie want a dingleball, bawwk! |