Thread overview
[phobos] phobos commit, revision 1689
June 24, 2010

--- On Thu, 6/24/10, Andrei Alexandrescu <andrei at erdani.com> wrote:

> On 06/24/2010 11:11 AM, Steve
> Schveighoffer wrote:
> > In defense of @property, I think we all agree we
> needed something to
> > distinguish setters from single-arg functions.  I
> think with a
> > reasonable rule, we can allow calling no-arg functions
> without parens
> > (via a proposal I made earlier that as long as the
> function returns
> > void, it should be allowed).
> 
> Fine, though that leaves writeln = 5; on the table.

No, those are single arg functions.  We need to distinguish those from property setters.  @property fits the bill well. I was merely pointing out that the need for that particular aspect of @property should be obvious, and as far as I know is uncontested.

What the calling no-arg functions without parentheses allows are things like:

range.popFront;

Where popFront cannot possibly be misinterpreted as a property because it does not return a value.

> 
> > All that's left is actual property
> > getters.  I can't say enough that @property in
> those cases has
> > nothing to do with functionality and everything to do
> with human
> > interpretation.  Like it or not, the use of
> parentheses is an
> > extension of the function name, whose semantic meaning
> of course is
> > unenforceable.  But just allowing the user to
> decide whether
> > something is a property or a function leaves the
> interpretation up to
> > the user, taking all the power away from the author
> who wrote the
> > function.  @property is a clarification tool, and
> by necessity, is
> > implemented via convention rather than compiler
> enforcement.
> 
> I've heard this argument before. I acknowledge there is a need to address unpleasant corner cases such as functions that return functions or delegates. What I'm saying is that the feature as designed hurts most for the benefit of a couple tiny corner cases. I've seen that several times in several language before. It's called bad design.

That is not my point at all.  Returning delegates from properties is a small problem compared to the one of name misinterpretation.

> 
> What I'm seeing in the field after faithfully using @property for a while fits my worst predictions:
> 
> 1. Code is sprinkled with @property so there's more syntactic noise to introduce and to deal with;

This is a non-argument.  Whatever is decided would certainly have to be "parsed" whether it was a comment saying "this is a property" or applying @property.

> 2. Whenever I define some function I need to make an arbitrary decision whether that will be a @property or not. Reasonable people could ask me why I chose whichever way I chose. (Most recent example: save() for forward ranges.) Arbitrary decisions are bad.

In the same *exact* way, reasonable people can also question how you name functions (I personally don't like the name save for that function, it seems like you are saving something on the range, not "give me a copy of this range").  Applying @property is a convention, just like camelCase, and there is no right or wrong way to do it.  Allowing people to optionally use or omit parentheses is the equivalent of users wishing to call your functions with their own preferences for casing.  It leads to confusion for others who don't use that same convention.  However, if you must declare the convention up front, there is no way around it -- you MUST use the author's convention, like it or not.  This leads to some grumbling, but mostly comprehension and consistency.

> @property is badly designed, no two ways about it. I now regret I didn't lobby more against it. I have a similar regret about lazy.

I disagree on @property.  Completely.  I have no opinion on lazy, I don't really use it too much or see the problems with it.

-Steve




June 24, 2010
On 06/24/2010 12:39 PM, Steve Schveighoffer wrote:
>> What I'm seeing in the field after faithfully using @property for a while fits my worst predictions:
>>
>> 1. Code is sprinkled with @property so there's more syntactic noise to introduce and to deal with;
>
> This is a non-argument.  Whatever is decided would certainly have to be "parsed" whether it was a comment saying "this is a property" or applying @property.

I forgot to mention: "... more syntactic noise for little benefit to show for it..."

>> 2. Whenever I define some function I need to make an arbitrary decision whether that will be a @property or not. Reasonable people could ask me why I chose whichever way I chose. (Most recent example: save() for forward ranges.) Arbitrary decisions are bad.
>
> In the same *exact* way, reasonable people can also question how you name functions

More of a bad thing is worse.


Andrei
June 24, 2010
Choosing a name for something is not bad, it's one of the artistic and subjective parts of programming.  Intuitive names can make a function/library so much better to use.  It's always going to be contested, and always going to be subjective.  What's worse is when people don't recognize a function by it's name because it has two different names, or don't recognize the functionality provided by a function/property because the wrong name is used.

I almost never have trouble deciding whether something is a property or not, and I use them all the time in C#.  That is, I never have any more trouble deciding whether something is a property or not than I do deciding the text part of the name.

-Steve



----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>

> > In the same
> > *exact* way, reasonable people can also question how you
> > name functions
>
> More of a bad thing is  worse.