Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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. metacpan.org) 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'

In reply to Re: Argument for Perl ( again and again ) by tobyink
in thread Argument for Perl ( again and again ) by heatblazer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found