Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Argument for Perl ( again and again )

by tobyink (Abbot)
on Oct 16, 2012 at 12:05 UTC ( #999304=note: print w/replies, xml ) Need Help??

in reply to Argument for Perl ( again and again )

Perl is not an OO language; it's a multi-paradigm language giving you the flexibility to mix OO code with other styles of programming.

Whatsmore, Perl's OO system allows you far more power and flexibility for OO code than Java or Java-inspired OO systems (PHP's is Java-inspired). And projects like Moose allow you to take advantage of that power without tearing your hair out!

Java's version of OO is very limited. It's single-inheritance, class-based OO. Many Java developers seem to believe that's the only true form of OO. Some will acknowledge that multiple inheritance is occasionally useful, but that it can also introduce problems (e.g. diamond inheritance). Few are aware that other entirely non-class-based forms of OO are also possible, such as aspect-oriented, role-oriented and prototype-based OO.

Here's an example in Perl (with Moose) using both classes and roles to take a plain old instance of the Person class and install a new method for that object only (not the entire Person class).

use v5.14; package Person 1.0 { use Moose; has name => (is => 'ro'); }; my $alice = Person->new(name => 'Alice'); my $bob = Person->new(name => 'Bob'); # Teach Bob to sing! Moose::Util::ensure_all_roles( $bob, Moose::Meta::Role->create_anon_role( methods => { sing => sub { say "lalala" } }, ) ); foreach my $person ($alice, $bob) { say $person->name, " can you please sing?"; if ($person->can('sing')) { $person->sing; } else { say $person->name, " cannot sing!"; } }

So even if Perl isn't an "OO language", it provides an arguably better and more complete OO programming environment than Java.

Also, while other languages may "have" regular expressions, these are generally just "match" and "replace" type functions which can be passed a regular expression and a string. In Perl, they're an integral part of the language...

use v5.10; my $count = 0; my $var = "foo <> foo <> foo"; $var =~ s ( fo{2} ) { ++$count; }gex; say $var;

Whatsmore, regular expressions in Perl are far more powerful. (More powerful even than those languages that provide the "Perl-compatible" regexp engine - this regexp library was compatible with a very old version of Perl; Perl's improved since then.)

Lastly, I'd say you undervalued CPAN. It's not just a repository of libraries; there's the whole infrastructure that goes with it:

  • CPAN Testers which provides a testing service for everything on CPAN on a variety of different platforms. They'll even test your code for free if you open-source it and upload it to CPAN.

  • The CPAN admins, whose existence ensures that should a module ever be orphaned by its developer, if there's a willing volunteer to take it over, they'll be given permission to do so.

  • The various CPAN websites (e.g. which make all the documentation on CPAN browsable and searchable, and link to reviews, issue trackers, etc.

  • The various CPAN installation tools that handle dependency resolution in a manner that rivals apt-get, etc.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999304]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2018-04-25 07:51 GMT
Find Nodes?
    Voting Booth?