Paul E Collins said:
Does anyone else think it would be nice to be able to write something like
this ...
public SomeType P { v; }
... rather than this?
public SomeType P
{
get { return v; }
set { v = value; }
}
I realise that the property construct allows 'get' and 'set' to do more
than
just assign or return a value, but in most cases - when I don't want to do
anything else - the standard form seems slightly long-winded.
I definatly agree, the syntax is long and not as clear as it should be. I
actually may be one of the few that thinks fields should be relegated to
sparse use and that the compiler\language should have made a greater effort
to remove the need for manual declaration of fields.
I've seen some syntax that suggests the addition of a property keyword
and\or a field associative keyword. Personally I like:
public property SomeType P{get;set;} //new keyword
or
public implicit SomeType P{get;set;} // saves a keyword, but overloads an
existing one
or just
public SomeType P{get;set;} //no keyword, but is it as clear as the above
and will people mistake it for abstract?
where the compiler generates its own field to store the backing type. P =
<value> in the declaring class calls set if its available but is transformed
into a field assign by the compiler when the property is get only. Similar
semantics could be performed for get if the property is set only. There is
some problem with that as far as how apparent the behaviour is within the
class. However I find it cleaner than trying to mix get, set, and a field
association into the property.