Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's great to see such an awesome Perl project on HN, especially these days when most folks here write Python, Ruby and JS and love to make fun of those "nerdy old Perl hackers".

I mostly use Python these days myself but I'll never forget the sense of power that Perl gave me when I learned it back in the late 90s (prior to Perl I had programmed in Turbo Pascal and Basic). To most programming enthusiasts back then it was what Python is today: A great, easy-to-learn, fun language that let's you solve almost any problem with just a few lines of code, mostly thanks to a huge ecosystem of powerful libraries (CPAN). Granted, the object-orientation felt more like a hack than a normal language feature (because it was one), but all in all it's still a really great language and just as powerful as Python, JS or Ruby.



If you haven't played with Perl lately, it's worth looking into Moose, an object system for Perl. It not only offers a much nicer syntax for making objects, but provides features like read-only accessors, roles, introspection, and even types! http://search.cpan.org/dist/Moose/lib/Moose/Manual.pod

I work with Perl professionally now after having spent most of my self-taught programming education using Python, and I've been pleasantly surprised with the language. I'm both coding new projects and working with a more than decade old code base, and I've found that Perl code is as good as the programmer.

Yes, like any decades old language it has its warts, but Perl 5 itself is still being developed and improved upon. For those who know another scripting language, the free book Modern Perl is a great place to start learning: http://modernperlbooks.com/books/modern_perl_2014/


Moose is very clever, but all that cleverness has a cost.

One of the things I like about Perl is that it offers tremendous performance, in addition to having an actually-useful debugger.

Subroutine calls in Perl aren't free; in fact they have a significant performance penalty if overused. And that's exactly what Moose uses, in droves.

Making Perl act like Ruby will also make it as slow as Ruby, and as difficult to debug.


Both Moo and Moose generated inlined versions of their constructors and accessors that mean that there's only a single method call being involved.

As such, runtime is just as fast as any other perl code that uses accessor methods rather than poking into its own internals.

Plus, of course, once you've got a Devel::NYTProf profile showing that a particular accessor is a hot spot, you can still poke into your own internals for that particular purpose to resolve the bottleneck.

So, no, not really; generally you only pay a cost for the pieces of cleverness that you actually use, especially given the existence of Moo for fast-startup code where you don't need the MOP.


Yes, so you can use Moose if you feel that it is necessary, Moo if you want something more lightweight, or nothing if you want speed. Just like there are modules for parameter type checking and all sorts of other nice features. My point is that Perl OO has some alternatives available from within Perl.

I don't know enough to vouch for Perl's performance vs other scripting languages, but I do know my boss (a very experienced Perl hacker) has a favorite saying: "If you wanted performance, why did you pick Perl?" :)


Total time = development time + run time

Perl might be one of the fastest languages from this point of view. I write 1%of my code in C and the rest in Perl for optimal efficiency.


Probably because he's comparing Perl to C.


They are looking to move part of Moose into the core I think. I haven't kept up much lately. They are also optimizing things in the newer versions.


> an object system for Perl. It not only offers a much nicer syntax for making objects, but provides features like read-only accessors, roles, introspection, and even types!

and even metaobject protocol


I've heard a lot of good things about Moose, the Modern Perl effort & so on. Enough that I periodically think about jumping back in the Perl waters. However, I always wonder if it's worth it, because Perl 6 is always "not far from release", so I figure I'll wait to check things out again.

Until the Perl community resolves the issues with Perl 6, the waters are too murky for a lot of otherwise would-be JAPHs.


Don't think of Perl 5 and Perl 6 as being like the Python 2 vs Python 3 situation. Perhaps a better comparison would be that of C vs C++: the latter is inspired by the former, but not everyone who uses the former has any interest (or needs to have any interest) in the latter.

Perl 6 is worth paying attention to, but not as "something which will make Perl 5 obsolete". Don't let the status of the various P6 distributions stop you from using P5 to make cool stuff today. :)


Perl5 and Perl6 are separate languages. Best thing is just to pretend that Perl6 doesn't exist. God knows everybody else does.


Those are separate languages, they shouldn't even have named "Perl 6" with "Perl" in it.


> Moose, the Modern Perl effort & so on.

That's mostly just a marketing ploy by a few people trying to make money off books and speaking fees. Ignore it.


Granted, the object-orientation [in Perl] felt more like a hack than a normal language feature (because it was one)...

Perl's OOP is definitely a hack! But it's a clever and elegant hack, and younger languages can learn a lot from studying how an awk++ managed to evolve support for all these new programming paradigms, without being totally co-opted by the ones which turned out to be fads. (When these languages are Perl's age, will they have evolved as successfully?)

Take OOP support in Perl. Prior to that, Perl had references, which could point to other basic value types, and it had packages, which were namespaces in the symbol table. Only two small changes were necessary for OOP.

First, a new built-in function `bless` was added which marked a reference as associated with a certain package. Second, a new binary operator for dispatch was added, the familiar `->` from other languages. The dispatch operator looked up a package from the reference on the left hand side, looked up a symbol within that package given by the right hand side, and pushed the reference onto the front of the argument list in the subsequent function call. In the called function, the initial reference argument became the equivalent of `this`, by convention.

Modulo some discussion of @ISA, that's it. You now understand Perl's implementation of OOP.

The elegance of this approach finally hit home for me when building transparent RPC for Perl and other languages. On the client side, when you dispatch a function call on a "stub" object, you'd like to dispatch a real function call on a remote object. In Python, you have to worry about whether you're calling a "bound function" on the remote object, versus calling a static method of the remote object, versus calling a "free function" defined at module scope (how do you address these?), and so on. In Perl, these are all effectively the same thing because the dispatch operator is so simple, and there's no extra OOP structure baked into the language itself like there is with Python.

Disclaimer: I mostly write Python 2.x now, but things like the complicated object runtime and the general uselessness of lambdas strike me as places where the language has stumbled.


Perl OOP is a hack, but coming from university where they taught Java, suddenly it made the whole thing obvious and transparent (to me at least).

Inheritance was no longer a black box, but just a way of working out where to look for the method and execute it.


Great answer, thanks for explaining this! I'm curious about how much this approach differs from the one pursued by Javascript, which seems pretty similar to me.


Javascript lacks the "packages" part of the mix, it uses Prototypal inheritance rather than Class based inheritance.

If you squint you can view prototypal inheritance as class-based-inheritance-where-everything-is-a-singleton ... but you really need some alcohol to deal with the headache you get from squinting that much.


> ... the general uselessness of lambdas ...

This sounds interesting. Why do you feel this way?


'sigil' referenced Python with "uselessness of lambdas", not Perl.

(If you still wonder -- from your comment history you shouldn't -- try Google: python lambda broken)


Slightly off-topic, but I can't help but commenting on your statement:

> To most programming enthusiasts back then it was what Python is today: A great, easy-to-learn, fun language that let's you solve almost any problem with just a few lines of code

I've been a part of an awful lot of different programming communities over the years. And somehow each one has a different set of languages they know and favor and have learned in the past.

What's more, they seem to think this same experience more universal than not. I've heard whole groups of people who claim in three part harmony that they love [X], and don't know anyone who's ever used [Y].

Every time I see a comment or blog post or tweet that mentions "that [Z] language and/or tool that we all know and love", I can't help but wonder which gated community they're a part of. It's just automatic now. Kind of like how every time I hear Canon in D, I remember the Pachelbel rant on youtube.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: