@property

Jonathan M Davis jmdavisProg at gmail.com
Thu Jun 24 13:43:26 PDT 2010


Pelle wrote:

> Also to disable writeln = 13;
> 
> But I want to keep paren-less calls and remove silly call-as-assignment,
> except for when marked as to make sense.

As I understand it, the whole point of properties in general is that they 
allow you to exchange public member variables and functions without changing 
code that uses the class. By being able to change a public member variable 
into a function, you can do things later on like add code to validate what 
you're setting the variable to or you can make the property computed instead 
of having an actual member variable for that data.

The fact that you can call all non-void single-arg functions and all void 
single-arg functions in D is purely a side-effect of the fact that property 
syntax was originally enabled in D by simply allowing all functions that 
matched the syntax of a property function - i.e. void single-arg and non-
void no-arg functions - to be called without parens. This lead to people 
calling non-property functions as if they were properties - writeln being a 
prime example.

Other than legacy, code I see _0_ benefit to allowing non-property functions 
to be called as if they were properties. They aren't properties and 
shouldn't be treated that way. Now, a programmer is free to use @property as 
they please in the code and can abuse it just like any other part of the 
language, but the whole point of being able to call functions without parens 
is in order to have property syntax for properties. I, for one, do _not_ 
think that non-property functions should be able to be called as if they 
were properties.

- Jonathan M Davis



More information about the Digitalmars-d mailing list