Do we want functions to act as properties, or merely omit parens for ufcs/chaining?

jerro a at a.com
Tue Jan 29 03:13:18 PST 2013


> I think the root reason why such confusion is the bad choice 
> that D made in the beginning, to define properties with the 
> same syntax as functions, while properties should be rather an 
> extensions of the variable concept, not of the functions 
> concept.

Properties should only appear to be variables from the user's 
point of view. From the implementation point of view, they *are* 
functions. So the syntax for getting and setting property values 
should be the same as for variables, but for implementing them, 
it makes sense to use syntax that is close to the one used for 
functions. That way, you can avoid verbosity and the need to use 
implicit parameters, like what they have in C#.

Current implementation of properties in D is not perfect, but the 
only issue with the syntax for implementing them is that there 
isn't a clear distinction between setters and getters, which 
leads to some confusion with global properties in the presence of 
UFCS. But that can be solved by having @property(get) and 
@property(set) or @getter and @setter. No need to adopt the 
inferior C# approach.


More information about the Digitalmars-d mailing list