@property - take it behind the woodshed and shoot it?

kenji hara k.hara.pg at gmail.com
Thu Jan 24 20:47:31 PST 2013


2013/1/25 Jonathan M Davis <jmdavisProg at gmx.com>

> And actually, something far more important than any of those reasons is the
> issue of setters. We've focused most of this discussion on optional parens
> and
> the situation with getter properties, but setter properties and their
> issues
> are also important. Would you want code like this to compile?
>
> range.popFront = 17;
> container.linearRemove = range;
> path.baseName = ".xyz";
> str.icmp = "hello";
> enforce(a == b) = "msg";
> arr.sameHead = arr2;
>
> With @property, we can restrict the functions which can be used with the
> setter syntax to functions where that makes sense. Without it, all kinds of
> ridiculous code like the code above would be allowed.
>
> Allowing optional parens is one thing, but conflating that with properties
> is
> something else entirely. Property functions are not just functions which
> are
> called without parens, and we shouldn't act like they are.


I have explained an additional rule in #1a.

> 1a. Optional parentheses for normal functions is just allowed for the
getter usage.
>
> int foo();
> foo(); // ok
> foo; // ok,  from #1
>
> void bar(int);
> bar(1); // ok
> bar = 1;  // disallowed, from #1a

 If based on that, such situations which you are worried will not occur.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130125/bfec9039/attachment.html>


More information about the Digitalmars-d mailing list