|The stupid question is the question not asked|
OO systems and Perl 5 (Was: Recap: Future of Perl 5)by RonW (Vicar)
|on Aug 28, 2018 at 23:50 UTC||Need Help??|
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:
Then to create an instance:
Doesn't that look a lot like:
For a friendlier object creation, you can define a class method to do all that:
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 UNIVERSAL.pm
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 UNIVERSAL.pm
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