in reply to Python OO v Moose
"there's a Python feature specific to OO that they really wish was in Moose"
I'd say the Moose OO model is far more powerful and useful than Python's. Roles, method modifiers, lazy builders, delegation and coercion are all really good for reducing repetitive code and improving OO design. With enough work most of that can be emulated in Python, but Moose gives it to you straight out of the box.
By the way; don't know if you're aware, but you can do this in Moose:
has [qw(arg1 arg2)] => (is => "rw");
Or of course:
has $_ => (is => "rw") for qw(arg1 arg2);
Also I'll offer a MooX::Struct example for your class. MooX::Struct is a compact builder for simple classes that mainly consist of attributes (not methods). It uses Moo which offers an easy upgrade path to Moose.
use v5.12; use MooX::Struct OurClass => [ qw( $arg1 $arg2 ), TO_STRING => sub { join "\n", @{+shift} }, ]; my $object = OurClass["Hello", "World"]; say $object;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Python OO v Moose
by Ea (Chaplain) on Feb 07, 2013 at 16:01 UTC | |
by tobyink (Canon) on Feb 07, 2013 at 16:43 UTC |