<div dir="ltr"><div><div><div>> We're using Class::Accessor, hence we have<br>> <br><span style="font-family:courier new,monospace">> $value = $foo->thing;<br>> $foo->thing($value);<br><br></span></div>
<span style="font-family:courier new,monospace">And what do you do if $value is undef? <br><br></span></div><span style="font-family:courier new,monospace">  if( defined( $value ) ) { <br></span></div><span style="font-family:courier new,monospace">    $foo->thing( $value );<br>
</span><div><span style="font-family:courier new,monospace">  } else { <br></span></div><div><span style="font-family:courier new,monospace">    $foo->clear_thing;<br></span></div><div><span style="font-family:courier new,monospace">  }<br>
<br></span></div><div><span style="font-family:courier new,monospace"><br>But I see Class::Accessor these days has hacks built-in to follow Damien's "Best Practices" if you like, or alternately to mimic Moose behavior. <br>
<br><br></span></div><div><span style="font-family:courier new,monospace"><br></span></div><div><div><div><div><div><div><span style="font-family:courier new,monospace"><br></span></div></div></div></div></div></div></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Oct 1, 2013 at 12:35 PM, Maxim Yemelyanov <span dir="ltr"><<a href="mailto:maxim4d@gmail.com" target="_blank">maxim4d@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We're using Class::Accessor, hence we have<br><br><span style="font-family:courier new,monospace">$value = $foo->thing;<br>
$foo->thing($value);<br></span><br>which clearly differentiates the set/get syntax.<br clear="all">

<div><br>- Max</div>
<br><br><div class="gmail_quote"><div class="im">On Tue, Oct 1, 2013 at 9:41 AM, Michael Friedman <span dir="ltr"><<a href="mailto:frimicc@gmail.com" target="_blank">frimicc@gmail.com</a>></span> wrote:<br></div><div>
<div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I agree with both of these opinions. In my last job, we had explicit get_title() and set_title() methods, but what we found was that we hardly ever called the set methods -- the values were almost always set when we got the item out of the DB. So optimizing for the get is a much better approach.<br>



<br>
In my current job, we don't do much OO Perl, but when we do we leave the get methods as just field name, title(), and make the set methods have some other name. We don't usually use set_title(), though, because we're setting it a particular way. set_title_from_feed() or set_title_from_clip() and so on, so that we can encapsulate different data-prep behaviors and have the function names be self-documenting.<br>



<br>
-- Mike Friedman<br>
<div><div><br>
On Oct 1, 2013, at 7:26 AM, yary <<a href="mailto:not.com@gmail.com" target="_blank">not.com@gmail.com</a>> wrote:<br>
<br>
> 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>
> -y<br>
><br>
><br>
> On Mon, Sep 30, 2013 at 9:20 PM, Joseph Brenner <<a href="mailto:doomvox@gmail.com" target="_blank">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" target="_blank">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" target="_blank">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" target="_blank">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" target="_blank">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" target="_blank">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></div></div><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></blockquote></div><br></div>