Perl is not Python, and other painfully obvious musings…

Posted by Elf Sternberg as programming, python

I’m prepping for an interview this afternoon at what is primarily a Perl shop, and so I’m mainlining the O’Reilly Perl in a Nutshell book as a way of reminding myself about the little details of the language. I can write Perl just fine– I just made some major hacks to dailystrips for example, and I write various renaming and text processing scripts all the time in Perl, because it is the language for that kind of thing.

But it’s little corners like, exactly what does bless do, that I’m reminding myself of. I know it’s the OO instance creation operator, and I remember the instantiation procedure but what exactly does it do?

So I go read the source code for Perl, in C, because that’s where the magic is kept, and I discover to my not-so-surprise that bless is a complete and utter hack. It puts a flag in the dereferencer to point to a different function, one that seems added after-the-fact, that instead of handling a procedure one way, instead just handles it another way with the recently dereferenced scalar as the first argument. That’s all it does. OO is so “bolted onto the side” of Perl that it’s amazing how important it seems to have become to the language.

But there’s so much missing from Perl; the whole metaprogramming capabilities of modern languages like Python, Ruby, and Javascript is just gone– done instead with code generation and eval, good grief– and yet the capacity for obfuscation is so terribly great. In many ways, Perl feels more like Bash scripting with a much bigger library of niceties and bolt-ons, which may explain why I use it that way.

5 Responses to Perl is not Python, and other painfully obvious musings…

Dave Doyle

July 10th, 2009 at 12:52 pm

“Bolted onto the side” or no, there’s tonnes of OO Perl out there. It’s not like it doesn’t work.

That being said, great things are happening with Moose (implemented via a Meta Object Protocol)… so I’m not sure what exactly you feel is missing. Head on to CPAN my friend.

Brian Wisti

July 10th, 2009 at 1:20 pm

Have you looked at Moose? (http://www.iinteractive.com/moose/)

It makes Perl’s OO bolts rather shiny and pleasant to look at.


July 10th, 2009 at 2:03 pm

Please…You don’t know Perl…Perl’s OO system is way more flexible than Python, but this requires black belt skills. Go read the book Object Oriented Perl. No one should be allowed to diss Perl before reading that book. Next, pick up Higher Order Perl. Then, realize how poor Python is.

Good ay to you, sir.

Mike Malone

July 10th, 2009 at 4:36 pm

Working as a Python programmer at what is primarily a Perl shop myself (Six Apart) I, too, have heard good things about Moose (and Mouse, which is apparently a related project?). Unfortunately I don’t know enough about Perl to comment on its utility.

After numerous conversations with colleagues on the subject, I do think OO in Perl is rather hackish. I’m not arguing that it’s inflexible. In fact, quite the contrary. Like many things in Perl-land it’s too flexible, too loosely defined, and lacks sane defaults for the common case. Any OO implementation where you have to define your own MRO is, in my opinion, broken by definition.

Python, on the other hand, offers the same rich feature set as Perl. I’ve yet to find anything you can do in Perl OO land that can’t be done in Python (and god knows the Perl hackers here have tried). But the default Python OO implementation is sensible. The syntax is reasonable, and you don’t have to worry about a bunch of stupid implementation details.


July 21st, 2009 at 4:11 am

Perl is a platinum bullet for all tasks

Damian Conway is like bap (father) of OOP perl. Read his book and come to discussions about OOP capabilities. After you read that book, you will feel that you aquired more knowledge.


Comment Form


July 2009
« Jun   Aug »

Recent Comments