views:

78

answers:

2

In VB.net the ANDALSO and ORELSE keywords should basically always be prefered over the AND and OR keywords.
What is the easiest way to disable the AND and OR keywords?
I'm thinking FXCop (maybe somebody has already written this rule).
Maybe just some setting in VS (we're currently using 2008 and are moving to 2010 end of the summer)

I'm open for all suggestions.

+1  A: 

Hehe, I think the solution you are looking for is called C#.

But seriously, using VB, you could go with some kind of blanket policy enforcement using FXCop or similar code analysis tools.

But when it comes to such a basic and fundamental feature as the language's core logic operators, you probably shouldn't mess with them even through policy enforcement. This is a training issue, and would be best addressed by training.

Detecting the accidental mis-use or unintentional use of these operators is best handled via unit testing or peer review. Basic operator behaviors are Chapter 1 stuff in any beginner's guide to VB, and no programmer should be working on real production code if they haven't mastered the basic syntax and operators of the language yet.

Stephen M. Redd
I'm a C# man at heart, but my company is Vb.net Although I see your point that I shouldn't be using the keyword in the first place, I don't trust myself enough to think I'll never accidentally do so. Hence the question ;)
borisCallens
I know the feeling... on the rare occasion when I work in VB, I have to remember to double check my logic operators for potential short-circuit flaws too.
Stephen M. Redd
I still stand by the advise of not disabling the operators, even though policy. While it makes us C# guys foam at the mouth, a lot of VB code actually makes use of the non-short-circuit behavior of the standard AND/OR operators. Makes me insane, but to the native VB guys it's just the natural way to do things.
Stephen M. Redd
It doesn't make me foam at my mouth. The fact that ByVal doesn't always send the value by val does though. This whole thing is more of a case of mistrust in myself...
borisCallens
A: 

The And and Or keywords have other uses besides just boolean operations. Performing bitwise operations is done by these keywords, so unless you can be absolutely certain that you will never need to do bitwise operations, you do not want to disable these keywords.

Gideon Engelberth
True, but uses are really limited. For these rare cases it would be perfectly ok to overrule the FxCop rule for that method.
borisCallens