Hacker News new | ask | show | jobs
by powera 1114 days ago
We are past the point where sigils are useful for a modern compiler or machine interpreter. A limited ability to avoid collisions with "reserved words" ... would be more of a mis-feature than a feature.

The value of a sigil is for the other humans reading the code. And, I agree it can be quite valuable there.

1 comments

> A limited ability to avoid collisions with "reserved words" ... would be more of a mis-feature than a feature.

While I don't necessarily disagree with you, there's something I'd like to mention.

C# allows using @ before a variable name which happens to be the same as a keyword to escape the name.

I don't remember the specifics, but it has saved me once when I wanted to create a class shaped exactly like a JSON object I was loading from an external source and one of the fields was a reserved word. For example, this works fine:

    class MyClass
    {
        public int value;
        public string @default;
        public string @switch;
    }
    
    string json = "{\"value\": 8, \"default\": \"something\", \"switch\": \"on\"}";

    MyClass o = JObject.Parse(json).ToObject<MyClass>();
    Console.WriteLine("default={0}, switch={1}", o.@default, o.@switch);