Language Devel / DIPs /
DIP5
DIP5: Properties 2
|
|
Abstract
An alternative design of properties. A variant of DIP4.
Rationale
Parts of DIP4 are too puristic. Especially this one:
|
Description
Namespaces were proposed as a solution for the properties problem:
|
They can be a cool feature but they don't look like properties.
Properties can be implemented similarly to namespaces:
|
Default storage is not a big deal to worry so much about it. The {get;set;} syntax exists in C# only for reflection purposes: librarier such as NHibernate are implemented so they look only for properties while serializing objects, so some default implementation for property-as-a-field is needed there. Another usecase for it is enforcing properties with interfaces, while most properties are trivial. And it seems to be the only usecases for default implementation for property getter, setter and backing storage. Though the same syntax is used for property declaration in interfaces. If one writes nontrivial getter or setter, explicit declarations of backing storage and setter parameter are no more an issue.
The problem with hidden backing storage is C# programmers for some reason used to access an event's invocation list and rearrange it, though getting access to it is tricky.
As to typename duplication, type inference can be used for opGet and opSet.
|
Interface declaration.
|
Problems
- Namespaces have the same ambiguity as current properties have, but in a more severe form:
|
|
So virtually no property member can be accessed reliably (guanteeing no clash with the return value members). This can be solved by making properties fully transparent as they are in C#.
- Possible misuse
|
- Peculiar ambiguity: with nested methods whether the member is a property or a function becomes a matter of minor detail: braces after the member identifier.
|
This may be not a big issue, but still...
Copyright
This document has been placed in the Public Domain.