Jimi-Carlo Bukowski-Wills said:
[snippetty snip]
You might do well to remember that classes are cleverly emulated in Perl
but don't actually exist (although I heard they might be available in a
later version)
What do you mean by that?
A Perl class is a (special case of a) package. A package is a (special
case of a) hash. In what sense does the class not exist?
Anno
Sorry, for top-posting...
what I mean is that it's not the same as classes in C++...
Well, me no speakee C++, so the comparisons are somewhat lost on me.
yes classes can be emulated, but there's no class keyword (in perl5) to
create a class, new is a sub you need to write yourself instead of being a
keyword to instantiate a class and there are not private/public keywords.
Perl was never really an Object Oriented language, it's just that [select
members of] the perl community has been clever enough to emulate it...
compare this will C++ which was specifically designed as OO, or Java, VB,
etc.
It is true, OO is only minimally supported in Perl. In fact, Larry Wall
has been quoted as saying it was an experiment in how little you can get
away with in an OO implementation. There was perhaps little choice
than doing it minimally, given that Perl existed as a procedural
language and had to be kept compatible.
I'm amazed at this discussion.
By your standards, C++ is not an object-oriented language either,
in that you do not have to program in an object-oriented style to
do stuff with it.
There exists object-oriented languages with no classes support. They
generally work by cloning existing objects. Perl5 definitely has
object-oriented functionality based on classes. Even if it calls classes
`packages' and if the method-binding operator is fairly low-level.
It has a fairly comprehensive set of object-oriented features, including
inheritance with all its needs, introspection, method-calling by name,
and polymorphism.
If it lacks anything in that area, it's probably that classes are not really
`objects' on which you can operate. It's a bit awkward to create totally
new classes at run time, compared to (say) smalltalk. But that didn't stop
some people, and since perl is interpreted, it's still possible to do this
kind of stuff.
Perl object-oriented core features are very small. So what ? you don't
need that much. You just have to tie methods to objects. Heck, anonymous
subs were already enough. All the rest is (mostly) syntactic sugar and
performance improvements.
The only place where perl is not oriented-object is that, yes, indeed
everything is not an object, like numbers and such. Most other languages
are that way either. Built-in numbers in C++ are no objects either, and
java has this weird concept of two distinct set of numbers (objects and
non-objects) to avoid performance issue.