With all the hype being thrown about Python v Perl and my own baby steps into Moose, I thought I'd have a quick look at how the other side does it and found both quite comparable. Not knowing any Python, I grabbed some code from a tutorial page and tried to implement the same 2 attribute, 1 method class in Moose.
class OurClass(object): """Class docstring.""" def __init__(self, arg1, arg2): """Method docstring.""" self.arg1 = arg1 self.arg2 = arg2 def printargs(self): """Method docstring.""" print self.arg1 print self.arg2
package OurClass; use Moose; has ‘arg1’ => ( is => ‘rw’ ); has ‘arg2’ => ( is => ‘rw’ ); sub printargs { my $self = shift; say $self->arg1; say $self->arg2; } no Moose;
For those who like their statistics simplistic:
  • Python (29 words, 190 chars)
  • Perl (25 words, 142 chars)

    Rather than seeking approval from any self-appointed echo chamber, I'm wondering if there are any here with the Python chops to tell me that I've created a straw man (like missing out the call to __PACKAGE__->meta->make_immutable;) or that there's a Python feature specific to OO that they really wish was in Moose or implemented more naturally.

    I'm not trying to get anyone's back up, just meditating on how to make the comparison fair.


    Sometimes I can think of 6 impossible LDAP attributes before breakfast.

    In reply to Python OO v Moose by Ea

    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, 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, 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.