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.

3
  • what if you want bitwise operations? :) don't tell me no one are doing them in VB, that's not true
    – user90843
    May 10, 2010 at 23:57
  • 1
    Very little. For those few cases the rule could be overriden. May 11, 2010 at 7:54
  • No quite. Remember VB is supposed to be a general purpose programming language. An used by more than one individual, each having different requirements.
    – user90843
    May 11, 2010 at 21:08

2 Answers 2

1

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.

4
  • 1
    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 ;) May 10, 2010 at 12:08
  • 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. May 10, 2010 at 19:25
  • 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. May 10, 2010 at 19:31
  • 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... May 11, 2010 at 7:16
0

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.

1
  • True, but uses are really limited. For these rare cases it would be perfectly ok to overrule the FxCop rule for that method. May 11, 2010 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.