proposal: @mixin functions to auto-mixin at call site

Timothee Cour thelastmammoth at gmail.com
Wed Sep 4 10:07:19 PDT 2013


On Wed, Sep 4, 2013 at 2:23 AM, Dicebot <public at dicebot.lv> wrote:

> On Wednesday, 4 September 2013 at 02:26:27 UTC, Timothee Cour wrote:
>
>> that's the whole point, it allows to transparently replace a field access
>> by a property function call without breaking client code. How else would
>> you do that?
>>
>
> You can't replace field access with function call transparently if it has
> side effects. In the end breakage may be even worse. For me only replacing
> @property fields with @property methods makes sense (with former prohibited
> to be taken address of and latter forced to be weakly pure).'
>

IIRC, &foo.x with x a property should take address of return value of x(),
which will either fail to compile or do the right thing if it returns a
lvalue. So there's no undefined behavior as far as taking address of is
concerned when replacing field by property.

As for side effects, this is the reason one would go from field access to
property, eg populating some data upon 1st access to a field x. Sure it can
be misused, but I haven't seen a case in practice where it is misused.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130904/589f69ff/attachment.html>


More information about the Digitalmars-d mailing list