views:

82

answers:

2

We have recently started using FxCop on our code base and I am in the process of evaluating the problems. One is the IdentifiersShouldNotMatchKeywords issue. This applies to a namespace company.blah.Event, which it wants me to change to something else as event is a keyword. The docs say:

When to Suppress Warnings Do not suppress a warning from this rule. The library might not be usable in all available languages in the .NET Framework.

under what circumstances might it not be available? Do I need to change this? I imagine that it is not going to be very popular.

+4  A: 

Different languages have different keywords. For example I can use If as a variable in C#, but if someone loads up the project in VB, they're screwed, any case like that can cause problems.

I'd change it, just to be safe. I'd say you need to change it if anyone else is consuming your library, you can't know what language they're going to use when doing so.

Nick Craver
+1  A: 

Well, it is a bit of a screwy message. It proclaims to know what the keywords will be in an as-yet unwritten language. For all you know, a future language like BrainFart may use Acme as a keyword, and you're screwed because that happens to be your company name.

There is a notable difference between the Acme and Event keywords though. The author of the BrainFart language will point out that you should have known about Event being a problem from running your code through FxCop. She'll win that argument.

You'd better change it.

Hans Passant
If you look at my example, it applies to current languages as well. Write a library in C#...make a VB.Net project, reference that C# assembly....immediate problems using that identifier if it's a keyword.
Nick Craver
@Nick: I don't repro that, the VB.NET compiler still treats "If" as a contextual keyword. This compiles fine: `Dim obj2 As New CSharp.If.Class1`. But that wasn't really the point of my post.
Hans Passant