new DIP5: Properties 2
Marianne Gagnon
auria.mg at gmail.com
Fri Jul 31 10:34:13 PDT 2009
>
> I think the poll might have been skewed due to context (forget my
> newsgroup poll, that was worthy of an abortion, but I also didn't mean to
> submit it :), I'm talking about Ary's)
>
> The question was asked, what do you think this code means. In the context
> of D, where you know a symbol without parentheses can mean either a
> function or a property/field, I'm certain there were several respondants
> who didn't understand it was asking what they think is best, not *what D
> currently does*. Ask that same questions to C++ developers and see what
> you get...
>
> It's hard to phrase the question properly without bias to a group of
> people who already know the current behavior. Maybe something like:
>
> Assume the D programming language required parentheses for normal
> parameter-less functions, and required no parentheses for parameter-less
> functions that returned a property. For example, the following code
> should imply a getter for a filter inside x:
>
> auto tmp = x.filter;
>
> And the following code should imply performing a filtering action using x,
> returning the result:
>
> auto tmp = x.filter();
>
> Do you think it's worth adding such a capability, given that you will then
> no longer be able to call ordinary parameter-less functions without
> parentheses, an author of a property function must properly indicate that
> the function is a property, and the compiler must trust the author for
> this implication?
>
IMP, the parenthesis thing is not about parameters vs function. I think the question is about whether the function can modify my object or not.
e.g. if I call
foo = object.x;
I assume 'object' was not modified. But if x can be like a function, disguised as a parameter, I can modify my object without knowing.
In C++, I'd say this behaviour is ok for 'const' functions. Now I haven't taken the time to study D constness, so I can't readily tell what is the direct equivalent, but I guess you understand what I mean.
In short, IMO everything that can modify my object should require () to stress that this is an action with possible side effects, not merely a getter.
More information about the Digitalmars-d
mailing list