i definitely agree with your assessement of: don’t do that. on a funny note, i have seen lots of things like the following:
int eger;
var iable;
bool ean;
I agree that you shouldn’t be naming properties and method names the same as keywords. However, this is not a simple problem with a cross language VM platform. If the compiled objects are language independent and each language has different keywords, then you will get conflicts as new languages are ported to the platform.
What Damien said. You’ve got a good example in the first code snippet there - the “Dim” keyword in VB.
“Dim” is not a keyword in C#. Creating an enum member called “Dim” in C# is perfectly valid, and doesn’t hurt in the slightest, so there’s no reason not to do it. If you want to access the code from VB.NET though, you need to know how it’s possible.
This goes both ways, and is not guardable against in a general sense as there’s no way of knowing what languages will get ported to .NET in the future (shudder - perl.net?), so it’s impossible to enumerate all the keywords that might be used by all of them.
"I don’t know that I would call two things that differ only in the case of the first letter a “better naming convention”. "
Yeah if you were naming two variables, then definitely I agree with you. But we’re talking about a C# keyword and an improperly cased enumeration (obviously judged by naming standards). What’s the problem with having an enumeration like this:
public enum Destination
{
Home,
Store,
Void
}
or
public enum UnionMemberType
{
Regular,
Delegate
}
none of these stand out as “wrong” to me, the casing differentiates it and follows my naming standard.
A man goes to a doctor’s office. He says, "Doctor, it hurts when I raise my arm over my head."
The doctor replies, “Then don’t raise your arm over your head.”
" “Dim” is not a keyword in C#. Creating an enum member called “Dim” in C# is perfectly valid
True, and worth thinking about. But you can use the [] or @ escaped identifiers to get around that edge condition. "
But it’s interesting because it means the keyword limiter is embedded in the compiler itself and not in the CLR.(if you can create enums of VB.NET keywords in C#)
Try naming conventions in SQL that can contain blanks? Order ID, Key to name a couple are pretty common column fields. Its just always easy as has been said above, to have variable names and enums that make sense within the context of things yet violate the keyword rule.
If a complier is smart enough to handle scoping and multiple iterations of a call and keep track of the scope of those iteratated variables that it would be able to hanlde something like keyword variable names. Wouldn’t it just be an extension of the scoping?
Maybe it helps porting code in which those weren’t keywords. Or somehow helps with autogenerated code. Or maybe an escape route for dealing with conflicting future keywords added to the language.
But I will follow another path than you. Your first example was :
Public Enum Test
Public = 1
Private = 2
End Enum
The compiler will say that you can’t use a special keyword inside Enum. But why ? My enum’s names will always be prefixed with the enum :
Test.Public
Test.Private
Can someone see where is the keyword ? All I see is an Enum identifier, followed by a name.
My conclusion is that the compiler is baddly written, because he can’t make the difference when “private” is a modifier or when it’s an enum name.