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. ;)
Published Tue, Mar 20 2007 9:47 PM by Rick van den Bosch
Filed under:

Comments

# re: Why would you?

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

Wednesday, March 21, 2007 5:33 AM by Ruud Campsteijn

# re: Why would you?

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

Thursday, March 22, 2007 6:13 AM by Sander van Kemenade

# re: Why would you?

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!

Thursday, March 22, 2007 7:32 AM by Jan Schreuder

# re: Why would you?

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

Sick...

Thursday, March 22, 2007 7:37 AM by Jan Schreuder

# re: Why would you?

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

Thursday, March 22, 2007 1:55 PM by Rene Schrieken

# re: Why would you?

Is it CLS Complaint? ;)

Wednesday, March 28, 2007 7:35 AM by P.J. van de Sande

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 3 and 5 and type the answer here: