Regarding the $a + $b vs $b + $a issue... Overload handles this transparently.

Lets say that $a is a Number::Fraction and leave $b alone for moment. If we say $c = $a + $b this will be magically transformed to $c=$a->add($b,0); But when we say $c= $b + $a there is only one circumstance where it will not get transformed to $c=$a->add($b,1) and thats when $b is both blessed, and has also overriden addition itself. In the latter case it gets transformed into $b->add($a,0) assuming of course the method in the other package is called 'add' as well.

This is quite unfortunate. $b might "bea" $a, but unless they're of the same class, $a won't "bea" $b.

The point of this node is to show that unless $b is also overriden your comment cant be true. And if $b is overriden then it had better have its own logic to handle the situation properly.

I do however agree with you and the OP that there is a problem here with inheriting the add method. It just wont work right in the child classes. But unless davorg had inheritance in mind I dont think its entirely wrong. Mostly maybe....


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: Re: if (UNIVERSAL::isa($r, ref $l)) by demerphq
in thread if (UNIVERSAL::isa($r, ref $l)) by hossman

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.