From: Dee Earley on
On 20/07/2010 02:48, Karl E. Peterson wrote:
> 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.

I'd use:
If Not SomeFunction(...

On looking through my own project, the only occurance of "If blah =
False" is your FindWindowList module :)

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
From: dpb on
Kevin Provance wrote:
....

> 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. :-)

I'd still wager the particular piece of code was written after its
author had just been indoctrinated in a defensive programming training
session or read the latest issue of one of the "C/C++ pitfalls"
columns... :)

--


From: dpb on
dpb wrote:
> 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).

And, of course, unless there's a specific reason to be testing
specifically for the FALSE case it's silly affectation to write anything
other than

if( !SomeFunc() ) { ...

anyway, in which case the possibility of an assignment by the "normal"
order in the case of the missing symbol doesn't appear.

I looked for the column but didn't find it quickly; the link to the
archived Embedded Systems Programming columns was/is broken and the
subsequent pages to the earlier ones after the first 10 all have the
same 10 columns linked to which didn't happen to include the one in
question. I have all the paper issues but not a generic index and it's
long enough ago I'm thinking I'll not be leafing thru to try to find it
that way any time soon... :)

--
From: Jeff Johnson on
"dpb" <none(a)non.net> wrote in message
news:i22ukn$oev$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?
>
> 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).

This is the explanation I've always heard, too.


From: Paul Clement on
On Mon, 19 Jul 2010 21:28:37 -0400, "Kevin Provance" <k(a)p.c> 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?

Looks like the Yoda School of Programming to me. Coded properly, the comparison to FALSE isn't even
necessary.


Paul
~~~~
Microsoft MVP (Visual Basic)
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Prev: Displaying property menu at runtime
Next: Delay Methods