Properties: a.b.c = 3

Chad J chadjoan at __spam.is.bad__gmail.com
Wed Jul 29 20:12:35 PDT 2009


Zhenyu Zhou wrote:
> 
> What about:
> 
> class Widget
> {
>  	Rectangle _rect;
>  	immutable(Rectangle) rect() const { return _rect; }
>  	Rectangle rect(Rectangle r) { return _rect = r; }
> }

You'll fall into the trap unless you know about immutable.  Said another
way: the default is unsafe.  Also this still isn't very useful, as it
still requires the calling programmer to manually break apart the
accesses and will not work for things like "array.length++;" which were
errors already.

So even if newbies were omniscient and always made their getters
immutable, all you'd have accomplished is turning a debugging session
into an annoyance.  Noble, but all too bitter when a complete solution
is within grasp.

This is also conflating the problem with rvalues-in-lhs with the issue
of D's lack of properties.  Forbidding assignment and mutation of
rvalues eliminates the debugging session.  The annoyance of "why won't
this work?!", well, that is for properties to solve.

See: http://d.puremagic.com/issues/show_bug.cgi?id=3008



More information about the Digitalmars-d mailing list