Ovid's Recap: The Future of Perl 5 got me curious, so I did some searching and found something interesting.

Object creation in Perl compared to Smalltalk (the putative parent language of OO languages): They are surprisingly similar.

Using Ovid's Point example, in Smalltalk:

Object subclass: 'Point' instanceVariables: 'x y ' x ^x x: coord x := coord y ^y y: coord y := coord init x := Float new. y := Float new.

Then to create an instance:

p := Point new. p init. p x: 1.5. p y: 1.5.

Doesn't that look a lot like:

my $p = bless {}, Point; $p->init; $p->x(1.5); $p->y(1.5);

For a friendlier object creation, you can define a class method to do all that:

newX: xc Y: yc p := Point new. p init. p x: xc. p y: yc. ^p


Point newX: 1.5 Y: 1.5.

Also, Smalltalk's new is a method inherited from the Object class and can be overridden by defining a new method as a class method of any user defined class. I'm leaving that as exercise for the readers.

So, maybe Perl 5's much maligned OO system can be blamed on Smalltalk. Not sure what else Larry et al had available to look at, but looks like Smalltalk had a strong influence.

Still, there is hope for Perl 5's OO system.

For those who've forgotten or are not familiar, Perl 5 has an equivalent to Object called UNIVERSAL. All classes in Perl 5 inherit from UNIVERSAL.

In theory, Perl 5 could provide a default new method for all classes by defining a new method in

Maybe Ovid can present a compelling enough argument to do that. That would be a great first step.

But, since I'm writing this comment, I'll suggest 2 additions to

sub init { # Nothing to do, this is just here so classes don't have to define + init } sub new { my $class = shift; my $object = bless {}, $class; $object->init(@_); return $object; }

I'm sure someone will come up with a better default new. This one is just an example of what could be done.

Disclaimer: None of this code is tested. YMMV