views:

50

answers:

2

In a lot of autogenerated code in Java, the common practice is to preface the name of variables that could potentially clash with user variables with a dollar sign. By convention, manually written code doesn't use dollar signs. However, in C# that character isn't valid in identifiers. Is there a standard practice for naming generated identifiers? I'm currently prefixing them with a double-underscore, which I believe is often used in C.

Sometimes you want to generate a superclass with certain functionality, and allow the subclass to wrap it up in a neat package. That's when this would apply.

+1  A: 

Edit: as Pavel points out, this does not actually work.

You may consider using the '@' character, which is usually used when trying to name a variable or field the same as a reserved word. i.e. @for since for is reserved:

private string @myString;
Kirk Woll
This does not prevent name clashes in any way. The identifiers `foo` and `@foo` are considered to be the same.
Pavel Minaev
@Pavel, great point, didn't realize that.
Kirk Woll
+2  A: 

I'm not sure what the standard convention is in this case, but since C# accepts Unicode characters in identifers, you could just pick a few arbitrary Unicode characters to virtually guarantee that no names will clash.

What are the odds of any variable starting with ꉜꈅ⣎, for instance?

Mark Rushakoff
That's a good idea, I'll use that!
MikeAinOz