News for hackers. Stuff that matters.
Re:C#'s Greatest Mistakes by Jon Skeet by AndrewDucker on Saturday November 27, 2010 @04:36AM (#1944686)
I'd love immutable auto-properties. They'd make a lot of my code cleaner.
Re:C#'s Greatest Mistakes by Jon Skeet by adambyrtek on Sunday November 28, 2010 @06:35AM (#1947168)
How would the fact that you cannot modify a property from within the class make the code cleaner? You can achieve exactly the same by sticking to a convention. It's impossible to fully protect a class from the inside anyway, so I don't see a lot of benefit from such a feature.
Re:C#'s Greatest Mistakes by Jon Skeet by AndrewDucker on Sunday November 28, 2010 @06:43AM (#1947178)
The automated property generators are just syntactic sugar. At the moment, if I want a property that's settable inside and out I can can type:

  public string MyString{set;get;}
In order to do the same with an immutable property requires a fair bit more code.

  private readonly string myString;
  public string MyString
  {
    get
      {
         return myString;
      }
  }
Replacing all of that with

  public readonly string MyString{get;set;}
would be handy, and work with the way the language currently does.
[deleted]
Re:C#'s Greatest Mistakes by Jon Skeet by AndrewDucker on Sunday November 28, 2010 @07:11AM (#1947209)
Oh, absolutely. It's not vital - it's just that with there being more multithreaded stuff going on I'd like easier ways of making it clear what's immutable and what isn't.

Heck, I'd love a way of saying "immutable class" in the same way you can with a "static class", just to ensure I haven't missed anything!

Re:C#'s Greatest Mistakes by Jon Skeet by adambyrtek on Sunday November 28, 2010 @07:18AM (#1947217)
I deleted my previous comment shortly after posting because I realized that you're right, this would be definitely useful. I haven't noticed that you already managed to reply to it.