Ran across an article on new features in C# 3.0 today, and one of the features listed is Automatic Properties. The general gist is that it's too much trouble for some people to implement a field properly, so the compiler supports a lazy way to do it. This:
private string name;
public string Name
{
get { return name; }
set { name = value; }
}Can be written like this:
public string Name { get; set; }So that's good, right? I'm not so sure. How is this any different from just exposing the private string in the first place? Like this:
public string Name;
Of course all of this is moot if you need to do anything more advanced in the property than just returning or setting the value. For example, logging or range-checking or limiting the visibility of the setter more than the getter. Something like this:
private string name;
public string Name
{
get
{
Log.Write("Name retrieved: " + name);
return name;
}
internal set
{
if(value = "this string not allowed")
throw new ValueNotAllowedException();
name = value;
Log.Write("Name set to: " + name);
}
}So, is it a big deal? Probably not. But it may make draft code faster to write, therefore it makes bad code easier to write because you get into bad habits.