views:

65

answers:

2

I found using AndAlso/OrElse, all the time, VERY annoying. It reduces code readability, especially when conditioning get complicated.

Any suggestions?

A: 

Are you saying that you don't like short-circuiting? Or you want the bitwise operators And and Or to short-circuit? Or you want the And and Or operators to be short-circtuiting logical operators for booleans and bitwise for integers?

Gabe
As I wrote, I want to use And/Or as logical short-circuiting.
How about an example?
dbasnett
+1  A: 

I'm fairly sure there's no (supported) way to change the meaning of And/Or, and assuming that your code might in the future be maintained or read by other people it would be a very bad idea, you'd confuse them completely.

If conditioning gets too complicated I'd suggest instead splitting it up on multiple lines.
so instead of:

If x AndAlso y AndAlso (z Or w) Then

Make it something like:

xy = x AndAlso y
zw = z Or w
if xy AndAlso zw Then
ho1
+1 This gives the opportunity to improve readability. `zw` could be renamed so it documents the meaning of the convoluted logic. I'd also suggest using the non-short-circuiting operators `And` `Or` most of the time, when it doesn't actually matter whether you short-circuit or not. That adds some more self-documentation, because the occasional use of `*Also` will stand out and emphasise that you are relying on the short-circuiting.
MarkJ