“AndAlso”…VB.NET short circuiting oddity
It comes as no surprise that Visual Basic frequently breaks away from traditional programming semantics, but the “AndAlso” short circuit conditional simply does not make sense.
For those not familiar with the short circuited conditional, it is a syntax where you can have two conditionals in an IF statement, and if the first conditional fails, the execution stops and does not continue with the second conditional. It simply saves the programmer the nested IF. For example:
If (thisBooleanObject && thisIntensiveBooleanMethod) {
Call thisOtherIntesiveMethod();
}
I really got used to using short circuited conditionals in the Java world, and I have been under the impression that VB.NET simply did not have this ability. When it bothered me enough, I did some research and found out that VB.NET does have a short-circuit operator called “AndAlso”.
“AndAlso”…….let’s think about that name. ‘If Condition1 AndAlso Condition2′, means we will not evaluate the second conditional if the first is not true. Does anyone else think this is kind of bassackwards?
Well, back to SQL hell.
May 25th, 2007 at 10:54 am
You’re right, sounds strange. back in the 90’s i’ve used to program Vax/Vms Pascal. There it’s called
‘If Condition1 And_Then Condition2′ dont know if thats better. Anyway its good it’s available.