Rick van den Bosch - Blog

... on .NET, software architecture, software development and whatnot

Why would you?

Last week I ran into a variable called @continue in the sourcecode of a project I'm reviewing. At first I had to think a bit before I knew what the @ was for. Of course I knew it's an escape character when used in front of a string value. But when used in front of a variable name? In that case, it is an escape character also, but this time for the name of your variable. This way you can use a reserved word as a variable name.

Why would you do this? What's so important about that exact name of the variable that it is not possible to think of a slightly different name which is not a reserved word? In this particular case, the boolean was used to indicate if the method it was declared in should continue parsing the next value in a foreach loop. I would call the variable 'continueParsing' or 'continueLooping' or something like that*. Those more clearly state the purpose of the variable, and don't make you escape your variable name. Furthermore it doesn't baffle 75% of the developers maintaining or reviewing your code because they don't know why the variable starts with an @.

Maybe I'm missing something. Maybe there are certain situations where this an absolute must. I can't think of one right now though.... can you?


* By the way, the best way would probably be to use a break statement, but that's not the reason I'm posting this for. ;)

Comments

Ruud Campsteijn said:

It's only required when all other possible member names are taken... all zillion of them :)

# March 21, 2007 5:33 AM

Sander van Kemenade said:

In Dutch we would call such a programmer an '@terbak'...

# March 22, 2007 6:13 AM

Jan Schreuder said:

Even developers that understand the concept of adding @ in front of a keyword will be confused. Why on earth would you need to do this? I would kick some serious butt if I knew who was responsible for this!

# March 22, 2007 7:32 AM

Jan Schreuder said:

You can just wait for someone to do this: bool @true = false;

Sick...

# March 22, 2007 7:37 AM

Rene Schrieken said:

Maybe if you are required to have domain classes that represents 1-1 the actual domain AND follow a non convetional naming convetion (properties in lower case)...

class Test {

string @continue{get{}set{}}

}

First finding: the domain class should follow the actual domain: remove the @ in front of continue

# March 22, 2007 1:55 PM

P.J. van de Sande said:

Is it CLS Complaint? ;)

# March 28, 2007 7:35 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)