Mark Michaelis' Weblog :
Updated: 9/1/2004; 7:03:28 AM.

 








Subscribe to "Mark Michaelis' Weblog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

Subscribe To
Mark's Weblog

 
 

Sunday, July 27, 2003

Using @ to Disambiguate Keywords from Identifiers in C#
Google Search It

While reading the C# Language Specification today I noticed the use of the @ sign to disambiguate a keyword from an identifier.  When you do this the identifier is called a verbatim identifier.  So, for example, you could write code as follows:

class @class
{
   
static void Main()
    {
        @static(
false);
    }

    public static void @static(bool @bool)
    {
        if (@bool)
            System.
Console.WriteLine("true");
       
else
         
System.Console.WriteLine("false");
    }
}

Why would you want to do this you ask?  Well, what happens if you use an assembly that has a C# keyword for a public name because that keyword did not happen to be a keyword in the original language of the assembly.   That would prevent you from calling this assembly perhaps unless there was a way to disambiguate. 

Another place I would be very tempted is in the name of the variable that is returned from a function.  Often it is difficult to come up with a variable name.  "return" would be great but it is a keyword so you have to resort to "ret," which is an abbreviation or perhaps result, which just isn't quite the same.  Now I can just use @return. 

public string GetName()
{
   
string @return;
   
Console.Write("Enter your name:");
   
do
   
{
        @return =
Console.ReadLine();
    }
   
while (@return.Length == 0);
    return @return;
}

Cool!  How 'bout making this a coding standard? 

I am confident this idea will get lambasted but I still like it... so there!


11:46:20 PM   []    comment []

Hanna Grows Up a Little More
Google Search It

Over the past month our 9 month old daughter Hanna has experienced a spurt in physical capabilities.  To start with she is pulling herself up to a standing position whenever near anything stable enough to support her weight.  Next, she is able to crawl up stairs unassisted which is most disconcerting because she has not yet mastered going down and doesn't seem to even be conscious of any danger when she attempts to go down head first.  Lastly, she even took a few steps with the push toy we have.  It was outside on the grass so it didn't role away from her too fast.

Another note is that she is starting to take a bottle (something she has refused in the past).  This means that perhaps mommy can get away for longer breaks as Hanna has already been eating solid foods for two or so months.


8:42:18 PM   []    comment []

Here's a great commuter car built by local Spokane residents none-the-less.  Their website is www.commutercars.com but the article provides a great write-up.
4:48:57 PM   []    comment []

© Copyright 2004 Mark Michaelis.



 


July 2003
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Jun   Aug


Recent Posts