[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl6-language
Subject:    The use of $!attr vs self.attr in core libraries
From:       Aaron Sherman <ajs () ajs ! com>
Date:       2016-09-08 13:55:50
Message-ID: CAN=dS7QngxSFYEcunJsWRgM5nZhjeLnam5Rh=3M8atpz2kJntQ () mail ! gmail ! com
[Download RAW message or body]

In working with Range a while back, I was frustrated to find that writing a
subclass that wanted to override an accessor (e.g. for $.min and $.max) was
quite difficult because most methods ignored the accessors and called $!min
and $!max or wrote to them directly. If I really wanted to change the
semantics, I pretty much had to re-write or at least wrap every existing
method, which would make my module nigh unmaintainable.

Is this for performance reasons? Would it make sense to try to find a way
to make this easier?

As a concrete example, here's how "elems" is defined on Range:

https://github.com/rakudo/rakudo/blob/32902f25ca753860067a34eb9741aa5524dbe64e/src/core/Range.pm#L96


--
Aaron Sherman, M.:
P: 617-440-4332 Google Talk, Email and Google Plus: ajs@ajs.com
Toolsmith, developer, gamer and life-long student.

[Attachment #3 (text/html)]

<div dir="ltr"><div>In working with Range a while back, I was frustrated to find that \
writing a subclass that wanted to override an accessor (e.g. for $.min and $.max) was \
quite difficult because most methods ignored the accessors and called $!min and $!max \
or wrote to them directly. If I really wanted to change the semantics, I pretty much \
had to re-write or at least wrap every existing method, which would make my module \
nigh unmaintainable.</div><div><br></div><div>Is this for performance reasons? Would \
it make sense to try to find a way to make this easier?</div><div><br></div><div>As a \
concrete example, here&#39;s how &quot;elems&quot; is defined on \
Range:</div><div><br></div><div><a \
href="https://github.com/rakudo/rakudo/blob/32902f25ca753860067a34eb9741aa5524dbe64e/s \
rc/core/Range.pm#L96">https://github.com/rakudo/rakudo/blob/32902f25ca753860067a34eb97 \
41aa5524dbe64e/src/core/Range.pm#L96</a><br></div><div><br></div><div><br></div><div>--<br \
clear="all"><div><div class="gmail_signature"><div dir="ltr">Aaron Sherman,  <span \
style="font-family:arial;font-size:small">M.:</span><div>P: 617-440-4332 Google Talk, \
Email and Google Plus: <a href="mailto:ajs@ajs.com" \
target="_blank">ajs@ajs.com</a><br><div>Toolsmith, developer, gamer and life-long \
student.</div><div><div><br></div></div></div></div></div></div> </div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic