[Purdue-pm] Perl 5 vs. Perl 6 object oriented programming
mark at senn.us
Thu Dec 15 00:27:49 PST 2016
PERL 5 OBJECT-ORIENTED (OO) PROGRAMMING
Moose is a complete object system for Perl 5. Consider any modern
object-oriented language (which Perl 5 definitely isn't). It
provides keywords for attribute declaration, object construction,
inheritance, and maybe more. These keywords are part of the
language, and you don't care how they are implemented.
Moose aims to do the same thing for Perl 5 OO. We can't actually
create new keywords, but we do offer "sugar" that looks a lot like
them. More importantly, with Moose, you define your class
declaratively, without needing to know about blessed hashrefs,
accessor methods, and so on.
Moose is based in large part on the Perl 6 object system, as well as
drawing on the best ideas from CLOS, Smalltalk, and many other
PERL 6 OBJECT-ORIENTED PROGRAMMING
Perl 6 is an object oriented language at its core, even though it
allows you to write programs in other programming styles.
Perl 6 has a rich built in syntax for the definition and use of
classes for object oriented programming, allowing for the definition
of state (as attributes) and behaviour (as methods) in the objects
of a class.
I prefer using Perl 6 which was designed and built with object-oriented
features built in over using Perl 5 with Moose. Offhand I don't know of
anything that Moose supports that Perl 6 doesn't support. If you use
Moose because you have code written in Perl 5 that you haven't converted
to Perl 6 see
for information on how to use Perl 5 from Perl 6. Perl 6 has many
features that Perl 5 doesn't have (see
https://docs.perl6.org/language.html and pages it links to). I miss
Perl 6 features when programming in Perl 5. See the "Basic OO in Perl
6" talk at
for how to do object oriented programming in Perl6 if you're interested.
It's harder to change the Perl 5 than the Perl 6 system software so I
expect more innovation to happen in Perl 6.
More information about the Purdue-pm