<div dir="ltr"><div><div>> Should look at Obejct::IndsideOut one of these days.)<br><br></div>The inside-out object fad seems to have cooled quite a bit.   Objects with perfect encapsulation sound like a good idea at first, until you realize that you can't debug them by just doing a <br>
<br>   print Dumper( $obj );<br><br></div>The Moose-heads seem to be winning the day, though party because there are lighter-weight workalikes around like Mouse and Moo. <br><div><br><br><br><br><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Oct 1, 2013 at 7:26 AM, yary <span dir="ltr"><<a href="mailto:not.com@gmail.com" target="_blank">not.com@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Been a while since I've done OO perl, but the last time I did on one<br>
of my personal projects, I used separate getters/setters- can't<br>
remember which format. (As for directly accessing href's, I'm<br>
heretical and often use array-refs when rolling my own objects, with<br>
"use constant" for field names. Only makes sense when your object has<br>
a mostly-fixed set of fields. Should look at Obejct::IndsideOut one of<br>
these days.)<br>
<br>
I suspect the common use of same setter-getter is due to it being the<br>
default for many modules (like Moose), and not from thoughtful choice!<br>
And I'd also think those modules were influenced by languages that<br>
have function signatures; languages where having the same name for<br>
getter-setter doesn't mean they call the same function because the<br>
arguments- or lack of- change which gets called.<br>
<span class="HOEnZb"><font color="#888888">-y<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Mon, Sep 30, 2013 at 9:20 PM, Joseph Brenner <<a href="mailto:doomvox@gmail.com">doomvox@gmail.com</a>> wrote:<br>
> I've always agreed with Rolsky: the getter form is far more common, so you<br>
> should optimize for that.<br>
> And I've always agreed with Conway that separate setters and getters were a<br>
> better idea than "mutators", where you use an undef argument to indicate<br>
> when you want to just do a get.<br>
><br>
> As far as I can tell, pretty much no one agrees with this, they much prefer<br>
> the "convenience" of the short form that does both functions... and they<br>
> tend to add additional methods in order to clear a field and set it to undef<br>
> (yup, that's convenient all right).<br>
><br>
> But then, where I work at present, most of the code just accesses the href<br>
> directly, which I gather is common at many places (e.g. Yahoo) and I<br>
> wouldn't swear that this is the wrong thing to do: there are decent<br>
> arguments against it, but they're not as strong as some people pretend.<br>
><br>
> For example: if you use accessors religiously, you then have the power to<br>
> write funny accessors that slip in magical behavior when someone tries to do<br>
> a simple get or set... but I find that when I do that, I tend to confuse<br>
> myself later: there's some odd code buried in a place where I normally<br>
> wouldn't look for it.<br>
><br>
><br>
><br>
><br>
><br>
> On Mon, Sep 30, 2013 at 3:55 PM, Kevin Goess <<a href="mailto:cpan@goess.org">cpan@goess.org</a>> wrote:<br>
>><br>
>><br>
>> Back in 2005 Damien wrote his now-famous Perl Best Practices, and<br>
>> recommended separate get_ and set_ methods for accessors.<br>
>><br>
>> I just now noticed a post by Dave Rolsky (himself no lightweight)<br>
>><br>
>> <a href="http://blog.urth.org/2011/03/23/reviewing-perl-best-practices-chapter-15-objects/where" target="_blank">http://blog.urth.org/2011/03/23/reviewing-perl-best-practices-chapter-15-objects/where</a><br>
>> he opines:<br>
>><br>
>> ---<br>
>> Damian wants you to write get_name() and set_name(). I don’t think this<br>
>> ever took off. My personal preference is name() and set_name(), though<br>
>> that’s just as unpopular.<br>
>><br>
>> I think the real recommendation should be to use read-only attributes as<br>
>> much as possible. Mutability adds complexity to your code. Avoid it<br>
>> whenever possible.<br>
>><br>
>> In that context, I’d avoid the get_name() style. Very little Perl code<br>
>> I’ve<br>
>> seen uses that naming scheme. The naming of writers matters less if<br>
>> they’re<br>
>> rare, but readers will be common, and you should just use the style that<br>
>> everyone else uses.<br>
>> ---<br>
>><br>
>> I've also rarely seen that naming scheme (and don't use it myself), but<br>
>> haven't done an exhaustive survey.<br>
>><br>
>> Does anyone else have a sense on how widespread the take-up of that<br>
>> particular Best Practice has been?<br>
>><br>
>><br>
>> _______________________________________________<br>
>> SanFrancisco-pm mailing list<br>
>> <a href="mailto:SanFrancisco-pm@pm.org">SanFrancisco-pm@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/sanfrancisco-pm" target="_blank">http://mail.pm.org/mailman/listinfo/sanfrancisco-pm</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> SanFrancisco-pm mailing list<br>
> <a href="mailto:SanFrancisco-pm@pm.org">SanFrancisco-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/sanfrancisco-pm" target="_blank">http://mail.pm.org/mailman/listinfo/sanfrancisco-pm</a><br>
><br>
_______________________________________________<br>
SanFrancisco-pm mailing list<br>
<a href="mailto:SanFrancisco-pm@pm.org">SanFrancisco-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/sanfrancisco-pm" target="_blank">http://mail.pm.org/mailman/listinfo/sanfrancisco-pm</a><br>
</div></div></blockquote></div><br></div>