I’ve been feeling hard done by with the Python folks talking down Perl and all this time apparently it’s been us Perl guys who think Python is a crippled toy.
I’ve never seen anyone say that Perl is a superior programming language to Python, because of limited lambdas, deliberately restricted recursion or anything else.
Good humoured ribbing aside (depending on where you sit I guess), I believe that Perl and Python sit at approximately the same level on the language power continuum. I mean, they’re similar enough to be two different people’s take on the same underlying language (I kid, I kid!).
I do think that Perl is strictly more powerful than Python (with e.g. parser flexibility, symbol-table hackability). However, in most cases this additional power isn’t something you need. The main places I can think of where it has been used legitimately is where stuff that is built-in to Python has been added by Perl at the library level.
While you don’t do too much symbol table manipulation in Perl on your own, you probably benefit from it. Libraries like Moose, or even good ol’ Exporter, rely on lots of symbol table manipulation. It’s features like this that make it possible to extend Perl without the internal devs having to modify the implementation. Pure-Perl CPAN modules can do a lot on their own.
Things like prototypes, overloading, and symbol-table hacking are changing the language. Not for the faint of heart but can be useful to make Perl more like other languages. For example, Moose changes Perl to look more like an OOL.
I’m not that familiar with Python but can it do arbitrary, nested data structures? That is the heart of Perl. How would you do this styled text example:
[
“This is plain text. “,
[
{
bold => 1,
},
“This is bold text. “,
],
“Back to plain. “,
{
italic => 1,
},
“Italic text. “,
[
{
underline => 1,
},
“Italic and underlined. “,
],
“Back to italic. “,
]
@Timm, @Shawn – sure, symbol table hacking and other unusual Perl features are handy for library implementers. I can’t think of any well-used libraries that implement anything not present in one of Perl’s competitors though.
@Shawn – yes, Python can do do arbitrary, nested data structures. Lists and dicts are effectively references too, so it can deference more elegantly than Perl was able to do prior to
5.12(edit – oops, 5.14 as Francis points out below).@Jared Okay with dereferencing you’ve got me looking at historical perldeltas now. Are you talking about the 5.14 change with the builtins accepting references and the + prototype?
I wasn’t bashing Perl! I was just saying that I brushed up on my incredibly rudimentary Perl knowledge and if the guy at http://www.perlmonks.org/?node_id=696592 is to be believed in Perl named nested functions misbehave in a variety of ways meaning lambas are the solution for scope problems.
So I said that in Python lambdas are limited and if you’re coming from Perl that feels catastrophic. But in Python you could use a named nested function where a Perl guy would use a Lambda to similar effect.
But what do I know – everytime a student asks me about autovivification I have to google it to remind myself what it is and then explain that Python doesn’t have that…
Re: “I can’t think of any well-used libraries that implement anything not present in one of Perl’s competitors though.” – Two very useful features provided by Moose are Roles and method forwarding (or delegation). None of Perl’s “competitors” have both of these features built in.
There are also simple freedoms like being able to write functions in any order, which I’ve missed when writing code in Python (Ruby doesn’t allow this either).
@Francis – yes, it’s the auto-dereferencing from 5.14… slightly concerned the talk is about killing it!
@Simeon – I know you weren’t bashing Perl! Your comments were pretty informative and constructive.
What I was saying is that it sounded though you felt that Perl devs looked down on Python (due to its limited lambdas vs Perl’s closures), which I don’t believe is true.
In fact, I suspect that the majority of Perl devs don’t use closures in day to day Perl development so the lack of them in another language wouldn’t be at all catastrophic. A half decent object system is a reasonable substitute.
@arun – I think you’re slightly misquoting me ( 🙂 ) and I really should look at the implementation of roles and delegation, but do they really hack the symbol table? I suppose they might.
Roles and Delegation both work by (programatically) adding new subroutines into a target package, so yes, there is symbol table hackery going on.
Example: https://metacpan.org/source/HAARG/Role-Tiny-1.003002/lib/Role/Tiny.pm#L334