Our differing opinions seem to come from the context we each envision when we think of coding. You seem to see the coder sitting down to write fresh code, I see the coder sitting down to look at existing code that needs to be understood and fixed or rewritten. That is how I spend most of my time and I am writing my own code from scratch.

I don't have any particular problem with the concept of calling "class methods" with objects

Likewise. I don't have a problem with that, I don't find the distinction "class" method very useful in Perl. In the case of new giving the reader more information about the type of the object can ease the understanding of code using that object. The reason to make my suggested usage a habit is that code can grow, an intermediate call may be inserted into your code; or code-text may be added around your construct making pertinent info more remote; or the type-tree may expand making the code more abstract.

if I am faced with $obj->method, and I need to discern which instance of "method" is being called, I'm going to be in for some work, no matter what. If there are multiple modules that might have "sub method" in them, whether I say ref($obj)->method or not will not affect the order of magnitude of the search.

You are exactly right. But the writer who says (ref $obj->method is explicitly telling you that the search is necessary. And the writer who says $obj->new when he knew that Obj->new was equivalent is abusing you unnecessarily, certainly there are some cases where the abuse is very minor, until the code grows.

A nitpick:(ref $foo)->method($foo) is not quite the same as $foo->method; the first passes two arguments -- the second but one. The additional argument in the first form does not provide additional information, but it is not quite correct to say that they "pass the same info".

Counter-nit: As you say The additional argument ... does not provide additional information so the statement is correct. I was trying to avoid the word pass but everything else I thought of seemed to relate to informing the reader of the code, which seemed more misleading.

I ... may be ... a stubborn git.

I won't dispute this, we both have demonstrated, ahem, a willingness to argue at length over minor issues. In that willingness I see fortitude and some concern for others and for truth. I am trying to share a Good Thing. I am not finding new ways to be more convincing on this so I'll let the subject lie.

I certainly am not going to have angina over this subject, I hope steves is not too worried for me. :-)


In reply to (Re:)+ $class = ref $class || $class by rir
in thread Constructor/Factory Orthodoxy by mojotoad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.