Why I still love Perl
allisonrandal.com
allisonrandal.com
I did it the old-school way with no fancy framework, just CGI.pm. I made fun of myself to my collegues saying it was great to live in the 90s again. But actually, after a few hours coding it became clear that we haven't progressed very far.
It was a single script and it just worked. It was also much more fun than persuading a web framework to do what I wanted because I was actually programming and not configuring.
Frameworks have got a lot to answer for; it's very rare that a large project actually gets to use the flexibility that a modern framework provides. Who the hell actually swaps out their ORM or their database for a different one in a production system? Sure, the lead architect was sold on the idea that they wouldn't be tied to a particular implementation, but when the shit hits the fan the business will deem it "too risky - find another solution".
Thus we advance to the third level of professional software development, the Sarcophagus model - wherein it's simply too risky to actually CHANGE any part of a (now-legacy) production system, but we CAN build a sarcophagus around the toxic core such that no more careers need be sacrificed to trying to maintain it. I have some great examples of this, but professionalism forbids me from relating them. Perhaps when I finally decide that keeping sheep on a remote island is preferable to being a software "engineer", I'll start writing about them.
I think that whoever says that Java is not good language for development either have seen only j2ee or never did looked around. (as a prime example the stupid bean convention and tools which operate on it)
The conceptual impedance of Java is just higher for me. I think most of the code I write (the non-algorithm complex stuff) that boils down to stuff like "take the subset of the collection of orders with a total over 100, and sort by number of items." In Perl, that may be as simple as:
my @large_orders = sort { $a->{items} <=> $b->{items} } grep { $_->{total} } @orders;
I think allowing me to express myself easily and succinctly like this saves time, reduces errors and allows me to concentrate my time and attention on the more complex portions of the code.I also think succinctness (where idiomatic for the language, so it's not confusing) is useful in it's own right. The more of the current (or related) function and program state that's obvious on the screen when I'm coding, the less likely I am to have to break off from what I'm doing to go look up a detail I need.
my @large_orders = sort { $a->{items} <=> $b->{items} } grep { $_->{total} > 100 } @orders;
Embarrassing.For the record, this would be the code with missing part included:
my @large_orders = sort { $a->{items} <=> $b->{items} } grep { $_->{total} > 100 } @orders;Well, after 3 years it's still plain perl CGI. Every web request, forks, compiles the perl code, compiles the template code, stat()s over 3000 Emacs builds and then renders the page. There is no caching. It's wrong my almost every measure of modern web code design. And yet, it's still fast enough for the amount of traffic it gets.
Oh, and it's still hosted by a computer in my house over my cable modem. Yes, it's a niche-y site, but it turns out that niche-y sites can still do a lot with a little, even on today's web.
What has always impressed me is the consistency and quality of the documentation of most CPAN modules. There's a huge group of people working at improving perl infrastructure and they don't get half the credit that they deserve!
Some examples:
http://search.cpan.org/dist/DBI/DBI.pm
http://search.cpan.org/~mlehmann/AnyEvent/lib/AnyEvent.pm
http://search.cpan.org/~melo/Redis/lib/Redis.pm
http://search.cpan.org/~abw/Template-Toolkit/
http://search.cpan.org/~ether/Moose/
It is just ridiculous. Searching around CPAN can become an odyssey.
[1] https://metacpan.org/ [2] https://metacpan.org/favorite/leaderboard
I agree with this. Is there any language that can compete with perl in documentation? For some big modules, they even have special tutorial for you.
Here's an example of how I use perl, off the cuff, in day to day production life: http://cautery.blogspot.com/2010/09/concise-perl.html
LAMP originated with 'PHP' as the 'P'. It's also by far the most common, for better or worse; 1.4M hits for 'linux apache mysql php' versus 50k for 'linux apache mysql perl' on Google.
Source for that? I certainly recall it first being used as either "Perl" or "Perl | PHP".
diff that against this one:
http://www.onlamp.com/pub/a/onlamp/2001/01/25/lamp.html
I love the obvious later edit:
"Of course, there are plenty of excellent open source variants for any of the pieces of LAMP. Let the L stand for Linux, FreeBSD, NetBSD, OpenBSD, and Darwin/Mac OS X, all of which are open source operating systems and all but the latter have open source GUI layers. Let the M stand for MySQL and PostGreSQL. Let the P stand for PHP, Perl, Python, and Ruby."
http://curtisquarterly.blogspot.com/2005/05/perl-tutorial.ht...
This illustrates the use of Perl in quick one-liners and helps understand why Perl isn't suitable for writing maintainable code. I've seen far too many cases of (and done it myself too often) assumptions like "there's no other tags ending in 'nk'" and "I can parse this XML/HTML content with simple regexps" in the quick & dirty code that is typical Perl (it works, let's use it...). This is where much of the productivity gains and "fun" comes from in the short term and where all the maintainability problems come from in the long term.
Evangelists will preach "modern Perl", good style and Moose to you, but these are half-baked, tacked-on solutions, they aren't fun and the overhead destroys the perceived advantages over other languages while not alleviating the massive disadvantages Perl has (performance, dynamic typing, lack of proper threading support...) over modern languages for medium to large size projects.
So, use if for one-off jobs and one-liners but don't get sucked into it for anything that intends to grow into a few 100 lines or more.
Disclaimer: I've used mostly Perl for ~15 years now and built a company with assorted technical debt, so this is biased on my personal hindsight. YMMV.
That's seems like a bit of a stretch to accept from a single anecdote.
> I've seen far too many cases of (and done it myself too often) assumptions like "there's no other tags ending in 'nk'" and "I can parse this XML/HTML content with simple regexps" in the quick & dirty code that is typical Perl (it works, let's use it...)
So you blame Perl for programmers making poor choices in how they parse their data?
> Evangelists will preach "modern Perl", good style and Moose to you, but these are half-baked, tacked-on solutions
How are they half-baked and tacked on?
> while not alleviating the massive disadvantages Perl has (performance, dynamic typing, lack of proper threading support...)
You mind supplying evidence for any of these? For some, dynamic typing is a feature. As for threads, I make heavy use of them every day, and while they have their quirks, they work quite well in some circumstances. Performance?
That wasn't a poor choice. I didn't propose "si.+?nk" as a general rule, and I would have used another method if there had been conflicting tags in the file.
I also take issue with the parent comment about perl not being usable for long scripts; that's nonsense. A comm framework I wrote in perl in '04 still sends payroll data for our 18k employees to the bank. It weighs in at around 400 lines, makes calls to gnupg, a database, has a scheduling engine that can parse cron entries, has support for EDI wrapping/unwrapping functions, logging, error alerting, other bells and whistles I'm forgetting right now.
There was nothing in the language that made this absurd or unsupportable.
I wasn't really speaking to any criticism of you in particular, but to the general statement about assumptions when using Perl.
I myself have used a regex to pull out well formed XML chunks and then re-parse them with a regex to build a hash out of the attributes of each chunk. It turns out it's 10x faster that any XML solution I could find (and there's quite a lot on CPAN!). The fact that it was a few hundred MB of XML and with a regex I could step my way through it probably had a lot to do with that...
That may have been true at one point, but what advantage does Perl now have to any number of other languages with great RegEx support?
I'll often need to pull some very specific information out of a very large log file, and often Perl is the quickest way to achieve that. i.e.
# pseudo-code
head -n10000 LARGE_FILE | perl -ne 'next unless my ($foo,$bar) = /include/gsmi; ${foo}+=$foo, $h{$bar}.=$bar}; END { print %h }'
Once you're happy with results on smaller data sets with head, replace with cat. I used a similar technique to quickly identify, classify and determine the user account for a large set of hacked Wordpress accounts at an ISP I worked for.Secondly, Perl is still the leader in regex development. They are still adding features that other languages are adopting (there have been a few good ides from outside they've taken as well, such as named captures, so credit where it's due).
We don't have many bleeding-edge Linux hackers pushing Ruby, Python, Mongo, etc., which in my opinion is a shame.
Perl works best as CPAN glue. CPAN is wizards handbook, and you just have to write maybe 100 lines of code to glue everything together. However when it came time to write a large project on a team of even 2 or 3 people, managing a Perl project seems to turn into manager a C project. The "Theres more than one way to do it" mantra really sucks for people who learned Perl in differently. 00's university perl doesn't mix well with 90's hacker perl.
My huge problem with Perl is readability. Sometimes, across teams, there are just too many ways of doing some simple thing and one is plain perl code to one person, is a 5-minute and stare at this line hack to another.
Am I wrong? My experience is limited, but I would love to know why I haven't been able to get my Perl projects to "sync".
To be clear, I don't know whether this is true, but I'm extremely interested in people results.
Also, once you know perl you can easily write "one-liners", which have made me incredibly efficient in certain cases.
I, personally, haven't noticed this happening any more in large Perl projects than with any other language. Yes they happen but, like with other languages, they're usually opportunities for team members to learn one thing or the other (either "this is what this does" or "please write comprehensible code to the rest of the team" depending ;-)
I personally haven't spotted Perl in the wild as a serious programming language for a long time. Again, it seems Perl is mostly popular with system administrators without much programming experience. But that might very well be just my little corner of the world, which happens to be a hosting company.
As many as PHP, Ruby, Python, etc. - maybe not. But new projects are still rolling out.
The Perl community is not so vocal, that's it and that's just pragmatic. Why yelling about nice tech you done? It works, it solves your problem, it's uploaded to CPAN, it's not a silver bullet, and that's OK.
Look at some Perl project like Cheater [2] - that's best tool for generation of test DB data available. Simple and extendable. And there's no hype about it. While I cannot even imagine an amount of hype if it were produced by Ruby guys (especially a couple of years ago) or NodeJS crowd.
[1] The bleeding edge in BigData'2013 - pipelening! So wonderful! Oh, wait a minute.. Is that Schwartzian transform we use from 1994?
http://shadow.cat/blog/matt-s-trout/names-and-numbers/
Plus many more posts by Matt, chromatic, David Golden, and Ovid.
Perl will always hold a special place in my heart and I will look back on it as the "good ole days", but I don't know if I'll ever program in it again.
It's not really a "Why you should use Perl instead of X" either.
It seems more like, "Perl's Not Dead, It's Just Schizophrenic Now". It attacks the idea of "Perl is Dead" with a description of the rather confusing state of "modern Perl". It doesn't exactly make the ecosystem sound all that enticing, not here in 2013 when there are so many other viable options.
These are the guys who if you Google their email address, it will show one or two posts to usenet between 1995 and 2013 and nothing else. No Twitter account, no Facebook profile, no prolific profile on Reddit or HN. Just silent work and go home.
Or maybe that's the wrong way to look at it.
When CPAN dies, perl dies. Is CPAN still my best hope for "easy interface to something really weird but very important"? Oh it is? Well then Perl it will be.
I find it extremely hard to justify on the job writing and debugging something that "just works" off a 30 second install from CPAN.
Note this criteria doesn't matter much for boring CRUD webapp number 246264. There are somewhat more optimized solutions for that very small subset of problems.
I think the "Why I love Perl" part is pointed out by the community and that Perl 5 basically spawned Perl 6, which is a different programming language.
I pretty much agree that Perl 5's popularity is really low, despite lots of great minds and exciting approaches. I switched to Node.js, CoffeeScript, Go, etc., but it is like everything I do could have been better or equally done in Perl and the tools were more mature. It's the same with all the new concepts and always makes me think about the MVC hype, when the concept of MVC was first named in the 70ies. It's a bit like with Smalltalk. It took like 30 years until people ralizing how good it is and reinventing it.
Same with "Do things the Unix way", pipes, KISS, NoSQL, distributed systems, all the stuff that the EC2 made popular. In that sense Computer Science is a really slowly developing science. At least it appears like that, maybe others are similar. I don't know.
And what is happening right now for example is making Javascript C, while the developers of C are stepping towards dynamic languages (Go). Also functional progrogramming laguages reappear, first Haskell, now Clojure reapear, cause it is cool for async stuff. LISP has been around for ages and Scheme is really beautiful and neither of them was ever slow or anything. Just look at Racket. It's pretty powerful, amazing to learn, performs at least okay and its IDE is pretty nice and cross-platform. It's amazing for doing the same stuff as Node.js and Scheme is one of the easiest languages to implement.
But back to Perl. It has a lot of problems. Nobody ever talks about how awesome CPAN and CPAN-Testers is (you don't even need to set up Travis CI). Nobody ever talks about it as functional programming language, even though there is a great book about. Another problem is that it is way more optimized for getting actual problems done and doesn't really perform too well, when you show your average snippet that looks mostly the same in every programming language out there.
The last flaw is that Perl is probably the hardest programming language to learn, because there are so many bad books out there. There are books like Modern Perl, that even are free, but also many really bad ones.
And a lot don't tell you about use strict; use warnings; use diagnostics; right away, even when they are what every beginner wants.
They even have a page dedicated to sifting through tutorials and guides, and assessing their usefulness for learning Modern Perl - http://perl-tutorial.org/learn/
"I sincerely hope to see Perl 7 released quite soon. No fuss, no bother, no long list of “blocking features”. Just BAM! ship the next version of Perl (5) as Perl 7. And I sincerely hope the greatest success for Rakudo. I don’t even care if it takes another 13 years to release, it’ll be worth the wait."
I remember a guy at a circa-2001 perlmongers meeting sullenly asking a visiting perl contributor "when is 6 coming".
The memory really influenced me. People really need a sense of momentum in order to feel confident in a community... same goes for a job and a lot of other things in life.
I'd recommend chromatic's Modern Perl (http://www.onyxneon.com/books/modern_perl/index.html) and Curtis Poe's Beginning Perl (http://www.wrox.com/WileyCDA/WroxTitle/Beginning-Perl.produc...) as good places to start.
The online (draft) version of Beginning Perl is available at http://ofps.oreilly.com/titles/9781118013847/
And s/he had some really nice friends. It was always fun, and interesting, hanging out.
I just spent a couple weekends putting that together. It's just a little toy, but it does exactly what I want, the way that I want it to.
I have to say I really enjoyed writing it. Specifically, writing it in Perl.
Writing Perl never feels like work to me. Can't say why, exactly. But I do know if I'd used PHP or Python instead, the pleasure of writing this app (as opposed to anticipating its completion) wouldn't have been there--I would have just persevered through it, in order to reach the final result. Totally different experience.
I 100% agree. It feels like having a fun conversation with an old friend. The kind of old friend you can not see for months, then pick up your last conversation again without any problem.
I think this really has to do with the language design being guided by linguistics principals than academic language design ideas.
With very little work, it's possible to write decently maintainable Perl as well.
>as a commercial artist you definitely wouldn't release anything new on it
ORLY? [1] Yeah, maybe Justin Timberlake or Jay Z will not release their, ahem, music on vinyl, but who cares?
[1] http://www.markknopfler.com/store/Product.aspx?id=SM001173
I'm not being facetious, I really want to know the reason I would do that. I buy the "Perl is better than C" argument 100%, but how is it better than Php, Ruby, or Python ESPECIALLY for someone picking their first server side language?
Personally, I'd avoid PHP as a first language because it's, well, kind of an abomination of a language even if the community have done some awesome things with it.
As for perl/python/ruby? I usually suggest to people that they should write at least some code in each of the three; you end up as a better programmer as a result and besides, it's fun :)
Things you might want to look at for Perl - Moose/Moo for OO, Mojolicious/Dancer/Catalyst for web frameworks, DBIx::Class/Rose::DB::Object for ORMs, App::cpanminus/App::perlbrew/local::lib for managing installations of Perl and modules, and http://metacpan.org/ for looking up libraries for everything else.
Also, the free book "Modern Perl" to get a feel for the language in 2013 as opposed to the hundreds of horribly outdated .com-bubble era tutorials you'll find on google.
You'd be best with somebody else's advice for python or ruby, most likely, so I shan't opine there.
Off the top of my head.
* I'd disagree that other languages have better libraries and frameworks than Perl. Perl has some pretty darn awesome libraries and frameworks.
* It has the best testing infrastructure in any language I have ever used. Period.
* The Moose OO layer has some really rather nice things for composing large OO projects
* Because something doesn't have to be better than another language to still be worth learning
* Because there's a shit load of perl out there - and knowing how to deal with it well will probably make your life easier.
* Because learning new languages always tweaks your perspective in useful ways in my experience
* Because the Perl "infrastructure" (CPAN, metacpan, CPANTESTERS, CPANTS, etc. etc.) is still best of class. I so wish I could have reports like http://static.cpantesters.org/distro/D/Dancer2.html in the Python, PHP, JavaScript or Ruby world.
* Because Perl takes backwards compatibility and keeping old code running very, very seriously. Shit just stays working.
As to your actual question, I'm not sure I'd say that Perl is better than Php/Ruby/Python. I really consider them all mostly the same. There are bits and pieces of each that is better than the others, but nothing overarching. If you know one of them really well, I don't see a huge reason to learn another one of them to the same level (unless some sort of outside influence compels you).
Perl's strength has traditionally been CPAN, but Ruby and Python both have their own copies and communities big enough that most of the stuff you look for is already there.
The Perl community's documentation is also superior to almost anything else out there. Once I've CPAN installed a package (say Template::Toolkit), I just "man Template::Toolkit" and there's a ton of documentation sitting there, including examples. The convention in the community is to put the example at the very beginning, which is heavenly, and cannot be appreciated enough.
In contrast, the Ruby community's documentation is largely a joke. It seems most of the time the documentation for a gem is in the README on github. And even then, to really learn it requires diving into the code. But then it isn't clear what is or isn't supposed to be a stable API. Perl seems to do that way better than Ruby.
Python always seems to have docs you can get to with pydoc but from what I've seen they tend to be auto-generated from the API with a lot of "FrotzBlubb() - This function Frotzes your Blubb" style non-documentation. So it has the sheen of documentation but it's not actually really helpful.
That being said, I learned Perl in 1994 or so and recently did a Ruby project. I quite enjoyed it and have been forcing myself to do new things in Ruby to keep up my language skills. I do miss the good documentation in Perl though (the Ruby community really needs to take note). Also Perl just seems faster than Ruby (I have no evidence, it just feels that way).
Anyway, from these responses, I would say there is no compelling reason to learn Perl as a beginner or advanced-beginner, but perhaps for someone beyond that point there are some decent ones.
Can anyone recommend good modern Perl book ?
I found really huge amount of Perl code in our Linux servers :)
http://www.catonmat.net/blog/perl-book/
You can read the first chapter here:
http://www.catonmat.net/blog/introduction-to-perl-one-liners...