207 points · by Mithaldu · 12y ago · 189 comments
My main job currently involves maintaining and developing a huge code base in Perl including three websites (soon to expand to much more). Perl just works. I thoroughly enjoy coding in it. I've not spent too much time optimizing and testing code though. mod_perl is pretty fast in itself (using Apache).
That being said Perl certainly lacks the in-built features which would make meta programming a quick and easy job. Yes, I still have to start using Moose. Perhaps in 2014!
Happy 26th Birthday Perl! Without you, I wouldn't have a job!
Video: https://www.youtube.com/watch?v=4YZNwO-uCVg Github: https://github.com/stevan/p5-mop-redux/
I'm personally interested to see how this develops.
As to my own Perl story, I used it exclusively in my first (non-student) programming job, back in the summer of 2000. I built an e-commerce website, CGI, with a cookie-based shopping cart. All from scratch, no frameworks, etc. I don't even know if there were any back then.
Fast forward to the year 2011. I started using Perl again, and loving it. Still use Perl every day. A fluid mixture of procedural, functional and object-oriented code. I really enjoy the language.
Then unfortunately I had to become more professional and started using my real name. :)
And it was turning a procedural mess into an OO mess.
Is there growth in the actual number of Perl full-time positions or is it declining?
Companies obviously need Perl programmers to maintain and enhance existing systems, but we don't see or hear about any new start-ups using Perl as part of their stack.
Fwiw: I don't use Perl anymore but was a fan and love Moose and CPAN.
Yes!
we don't see or hear about any new start-ups using Perl
The world is a lot bigger than just startups, but see:
At the end of the day I find I prefer perl for quick things, and Python for multithreaded things.
Contrast with Python's philosophy: https://wiki.python.org/moin/TOOWTDI
Python's philosophy may be limiting for some people, but I'd rather have code that I have a decent chance of reading and understanding the run-time behavior of than a language that encourages extreme personalization.
The whole parsing thing doesn't help either: http://www.jeffreykegler.com/Home/perl-and-undecidability
And secondly its extremely rare that you will run into some obscure feature which indulges in the whole parsing thing you mentioned.
For me...
* perl is a bit more intuitive, even though I've done about as much python as perl at this point.
* It's the best language for dealing with regular expressions in my view. You don't have to create a regex object and muck about with all of that.
* You can create lambdas/closures with fewer restrictions than Python (this is a big one)
* CPAN is pretty good. Python comes with a lot of libraries, so this isn't as much of an edge as it used to be.
* It is more widely available on other servers, even older ones, which is important for me because I'll sometimes have to do work on a machine without Python already installed. I can work with older perl and I've never been on a machine without it installed.
* The whitespace issue really is annoying to me. With braces you can move stuff in and out of conditionals, etc, easier than with Python, even with editor support.
As for readability, I try to write reasonably well, even if in a hurry. I know the language and its syntax. I understand the purpose and meaning of the sigils, so it doesn't look like noise to me anymore than reasonably written python. In Python, for instance, I've seen list comprehensions that are pretty frustrating to puzzle through. Perl with strict and warnings and written without a specific aim to be clever isn't hard to read.
When I was at Google I started using Python to create a CMS of sorts for my toy website (robotics.mcmanis.com) which got to the point of being able to push some stuff but more complex stuff was a pain. So it sat there. Then rebuilding that with perl and the template toolkit it was a bit easier and I was much happier with the result. I still don't have a lot of time for it (like none for the last few months) but I got the framework for putting up a new "article" down to a pretty smooth process and managing all the internal links worked well.
Perhaps it is that I programmed in C for so long that my synapses are more attuned to reading code with braces. But I find I can look at perl and intuit its function much more quickly than I can do the same for Python.
I assume you mean named captures?
C:\>perl -E "'abc1234asf' =~ /(?<one>\d+)/; say $+{one};"
1234
> template toolkitPlease try Text::Xslate. :)
Python is in that respect essentially the same as Perl with Coro built-in. ( https://metacpan.org/pod/Coro )
That said[1], I probably feel the same way about the use of 'because' in informal speech. Which was recently upgraded to include the form "because <noun>." I don't find that a particularly compelling upgrade.
[1] Another habitual favorite of mine.
---
I think what gets me about leading with "So" (more so in spoken converstaion) is that it makes the speaker sound like they're constantly, and consciously, having to reframe things in a form that the poor dummy they're speaking to will understand.
Politicians do it a lot when answering questions.
I also recognise that it's more innocently used when telling a story.
http://chronicle.com/blogs/linguafranca/2011/12/02/so-it-tur...
(Predictably the Chronicle article has a bunch of comedy geniuses using it as a comment!)
It was my first exposure to dynamic programming languages (unless you consider BASIC one). I started out on BASIC on an Amiga 500 then C on my first DOS 386 computer (I just wanted to learn to make games). I came across Perl in my final year of high-school when at a co-op placement with a local web development shop. The school taught Pascal and a little-known language called, Turing. Scalars were super-cool by that point.
It's amazing to see how far things have come and that Perl continues to get better despite the downward trend in its popularity in recent years.
Here's to another 26! :)
Evaluating other environments along those lines yielded interesting frustrations. In my opinion, the real contender is node.js, thanks to its minimalist approach on many things, and NPM.
Note: I'll admit that Node forces you to be as async as possible, but it's for a good cause so I can turn a blind eye on it. :)
Been programming in it full time ever since.
Thanks, Larry Wall, Randall Schwartz, Brian Foy, Nat Torkington, Tom Christiansen, Damian Conway, etc. etc.
Count me in as another person introduced to O'Reilly via "Programming Perl." Was "Perl Best Practices" the first such "Best Practices" book?
"Programming Perl" is not just (very) informative, it is also engagingly, even entertainingly informative.
(Proof of this is left as an exercise for the reader... ;-)
Although, I clicked through the pop-up link, to find a fairly brief and limited set of points in a short, single critique of the 4th edition.
I don't know... It's been a while, but I still remember "Programming Perl" as providing not just the what but a good dose of "why" and context.
A lot of people who "don't like Perl" don't seem to understand that, where it's coming from, both philosophically and systematically (if that is a word and I can use it here).
"Programming Perl" is not, in my opinion, a beginner text. Randal took care of that contemporaneously with "Learning Perl". But it was, and -- current shortcomings aside -- perhaps still is, a good post-beginner text.
It also remains "timeless" for me, in that it was a good, engaging read. In my opinion, more texts should -- if clever enough to -- dialog with the reader rather than spewing at them.
Anyway, I don't mean to put myself in the position of defending Larry et al.'s tomb in this post-post-modern world. I'm hardly qualified to begin such a task.
But even if it's not currently the best reference, or even recommended as such, I think it may remain a decent example of how to write one.
I once had to work on a an ASP (MSFT Active Server Pages circa 2001?) website that was written with ActivePerl [1]. Their technologist chose it, then left the company, and they had a hard time finding someone to work on it.
Also, the Programming Perl book was my first O'Reily book that I read/used, checkout out from campus library.
Ahh...memories.
And yes, as the article says, Here's to 26 more! :-)
Right now I'm a huge Scala fan. I've had that experience of feeling that I never want to program in any other language again (and every other language I've gone to, even those I used to like, feels clumsy and tedious by comparison). But I hope that in 25 years' time I'll have moved on to something even better. Language design isn't done, and languages are getting better all the time.
That is actually what Perl is doing. With its loose original design it can evolve amazingly, and in ways that couldn't be foreseen.
It's a language for people who are comfortable enough around theory that they don't need syntax to force them to use it.
At the same time, it's highly evolutionary -- it supports the fastest, dirtiest, hackinest method of getting to the goal -- and thus has prototyping built in to production.
I often write Perl scripts twice. The first is a tape-up job to "git 'er done" and the second is a more elegant and architected approached.
This method matches the configuration of most jobs. The client doesn't (fully) know what they want. Last-minute, world-bending exceptions arise. Well-intentioned schemes gang aft agley.
With this prototyping-production, I'm able to get something up and working, and can fix it later if the client has foresight.
Theory is great. I am the first to defend theory. But if it doesn't correspond to application, there's another word for it: arbitrary.
(You may note the difference between two predominant value systems illustrated in that sentence.)
I was used to take a problem of a certain size, sit down and think for a while. Then code C for maybe 3 to 10 days.
When I did a similar problem in Perl, the time to think for a problem of that size was longer than the time to throw a solution at the wall! You could design using code, then refactor/rewrite if it got too bad.
Best of all: So much more fun.
no less can I say;
require strict, close attention
while you ... write haikuPerhaps my favourite memory of the Perl scene was the announcement of Parrot - an April Fools joke that detailed a project to built a bridge between Perl and Python - that then got built. Brilliant.
With PHP, Python, Ruby and Javascript... space seems tight for another scripting language. Languages like Lua have something special. What's special about Perl?
Edit: I don't want to be hateful. The more the merrier obviously.
The original killer feature of Perl was regexs - these existed before, but Perl's implementation destroyed all others, and 'PCRE' (Perl compatible regular expressions) became the default - most modern languages use PCREs for their regexs.
There was some bad stuff that happened with this too - people used regexs for ghetto, half-assed versions of tree structures like HTML and XML - but for the task of chewing through Unix config files, up until around 2005 Perl was unbeatable because of the awesome regex support (and because it's history meant, at the time, perl was installed on all Unix boxes).
Also a note about the sigil: Get a decent syntax highlighting set up for your editor and you'll quickly realize how nice it is to have functions, variables and different variable types colored differently.
print x if x > 5
is problematic in p5 for a whole bunch of reasons:(1) At a bare minimum, what you really need to say is:
print "$x\n" if $x > 5;
That extra "\n" is a definite turn-off to a lot of people when the get their very first look at Perl. Really, the default these days should be more "say"-like. Of course, "say" is there as of 5.10 if you know where to look for it, and you go out of your way to enable it: use feature 'say';
say $x if $x > 5;
(2) In "modern", better practice, production-quality Perl you pretty much have to either hedge every comparison op with a check for defined-ness: use feature 'say';
say $x if defined $x && $x > 5;
in order to head off an unsightly warning about $x not being initialized: Use of uninitialized value $x in numeric gt (>) at print-if.pl line 5.
or add even more boilerplate to suppress the warning: use feature 'say';
{
no warnings 'uninitialized';
print $x if $x > 5;
}
or be very attentive about how $x can mutate once it's gotten passed whatever validations you're imposing on it before it enters your scope -- via e.g. Params::Validate, Method::Signatures, provided you know these tools exist and are up to speed and hip as to how to use them effectively.(Yes, I know that in some contexts, the warning on 'uninitialized' can be very useful. But my point is, most of the time, and especially for novices, it's more of a misfeature).
(3) We shouldn't gloss over the fact that the magical pseudo-grammatical construction the "infix" if syntax provides is itself problematic in many ways.
In the current example, it simply isn't clear -- until you've become very comfortable with the language! -- if the original statement
say $x if $x > 5;
is or is not equivalent to the very similar construction $foo = $x if $x > 5;
say $foo
This is because it is by no means obvious as to which of the more "active" parts of the original expression -- either the "verb" (print) or the conditional (if) -- takes precedence.And unfortunately, it's not only possible, but terribly easy to "whip up" fare more volatile constructions like this in Perl 5. Various on this theme -- gotchas about print, conditionals, and complex "if/unless" constructions -- were of course given ample treatment in Perl Better Practices, to the point where (I believe) that Damian pretty much eschews "trailing" if/unless constructions altogether.
(4) Lastly, it's sad to say that for all the complains of Python having too many safety belts and what not, it completely nails the hidden complexity management issues embedded in such a simple construct like Perl's "print-if" idiom.
In Python, basically the only sensible way to achieve the original desired result is to do this:
if x > 5:
print x
Perfectly clear, completely unambiguous, and basically impossible to screw up.Isn't it? If someone told you, really you to do just that, would you actually have a problem carrying out that command given a way to print something, a container, and a value to check against the container contents?
Also, here's me preference:
say $x if $x and $x > 5;
Need to catch zero? say $x if defined $x and $x == 0;Its true. Perl feels like a very powerful base language, moving to Python felt like you were taking a bit away (I know in reality you can probably achieve much the same things). Python on the other hand doesn't require you to implement your own basic functions (max, min , trim / strip ) as they are included already. Python stops me from shooting myself in the foot as often, by not allowing me to do stuff that is too clever too early.
I do miss being able to reference / deference variables explicitly though. Other great things are, CPAN, regular expression support (that never feels as nice in Python), one liners for doing stuff quickly on the command line. I even quite like the sigils, as an easy way to recognize the types of variable you are dealing with (though it is confusing at first). Working with strings feels a lot more natural in Perl than Python.
But Perl-like ambiguity still seeps into your English. Was that Python 3, or 3 years ago?
(Ok, I just checked, Python 3 has been around longer than I thought).
Or even better, just use List::AllUtils - https://metacpan.org/pod/List::AllUtils
I'm not trying to dump on perl. I love C and C++ and those get dumped on all the time and I hate it. But anything I could do in Perl I instead do in Ruby. It's not as fast, but if fast matters I'm not supposed to use a scripting language.
Perl can actually be very fast; it depends on what you're doing and how you write it. A lot of developers don't realize that Perl isn't really a scripting language; it's a compiled language that has a compiler that's so fast it can be run every time you run the program. The compiler produces bytecode, and the bytecode runs on a virtual machine, just like Java and C#.
The key to writing fast Perl code is to use programming constructs that compile down to single bytecode operations, because those operations are implemented in the VM using well-tuned C code. For example, using grep and map with array variables is much faster than using a for loop and explicitly indexing through the array. With the former, the enumeration is handled in C code, while in the latter it's handled in Perl code.
Note: that's probably not 100% accurate, but it's the general idea. You can actually have perl output the bytecode it generates so you can take a look at it, and figure out places where changing how your code is structured will produce more efficient bytecode.
Perl has a minimal std library, to teach people to use CPAN I guess. But even Perl has util modules for trivial help functions in the std install (at least those which aren't one line of code to define).
The strongest argument for Perl today is CPAN and CPAN Testers, still the gold standard.
But all the scripting languages are really similar, there is no reason to learn another if you already know one.
Edit: You might want to check out the Modern Perl book, free online. Perl evolves quite fast.
I started using Perl on VMS, where there was no sed, (g)awk was new, no grep ("search" did not handle regular expressions, "find" did but arrived very late); and the command language, while sane, was very slow. Perl's system integration on VMS was excellent.
That's an ironic statement, since Perl came first and was absolutely dominant in the domains which PHP, Python, Ruby, and Javascript now occupy. When they were young, it would have been reasonable to say that space seems tight for another scripting language because we had Perl.
Languages like Lua have something special. What's special about Perl?
What's special about Lua? That's a four-word question that could require a huge response. Lua's a nice little embeddable scripting language, but that's a niche that Perl has occupied too. It's got fantastic support for both being embedded (callable from other languages) and embedding (able to call other languages). You might say that Lua's better because it's smaller and cleaner and simpler, but that's only true until you run into Lua not being powerful enough for something you want to do. If you used Perl as your embedded scripting language instead, you probably wouldn't have that problem. (Other problems, maybe, but not a lack of power.)
[$x => $y]->[$x <= $y]
Holy shit - just realized I first touched Perl 15 years ago! $x > $y ? $x : $y
in this use case, then you have way too much time on your hands.[$x => $y] creates an array reference. => is just a fancy syntax for a comma. So its actually [$x, $y].
[$x => $y]-> dereferences the array ref.
$x <= $y is a boolean expression which return 0 or 1. Accordingly the array index is chosen.
Sorry if I'm unable to explain properly! Here's a script.
#!/usr/bin/perl
use strict;
use warnings;
my $x = 8;
my $y = 9;
print [ $x => $y ]->[ $x <= $y ];- Why does the array have to be explicitly dereferenced? Isn't it obvious from context?
- Why count on the mapping from boolean to int being false = 0, true = 1? Pretty much everything other language that has such a mapping does false = 0, true != 0.
In one line, a vivid reminder of why I find perl so awful.
If not for Perl Monks, my enthusiasm might have been lost midway.
http://perl.apache.org/docs/index.html
You can wrap your existing CGI scripts in it using
http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html
so the transition can be rather smooth
For example: emacsformacosx.com was straight Perl CGI until about 2 weeks ago.
However, in recent years PSGI has started to become the standand in the community. As far as I know, it is modeled after Python's WSGI. All of the "major" perl web frameworks support it, the three big ones I can think of are Mojolicious[1], Dancer[2], and Catalyst[3].
1: https://metacpan.org/pod/Mojolicious
It's really nice, though. Try out Mojolicious::Lite asap!
If you can't go to the modern frameworks, I quite like Dancer myself, you can get an ebook from O'Reilly (or used).
1: http://www.modernperlbooks.com/mt/2011/03/why-psgiplack-matt...
2: http://search.cpan.org/~miyagawa/PSGI-1.102/PSGI.pod
D'oh! Now I see below that your duplicate of this question got the love it deserved already...
Side note: I have noticed that in bioinformatics, perl is largely being replaced with python in tool usage.
Which has honestly little to do with the language and more with the fact that the bioinformatics-related Perl books are the worst programming teaching books i have ever seen. (Honestly, a lot of the flak on perl goes back to old and outdated books.)
It was for the 90s and 00s what Microsoft BASIC was to the 1980s.
However, I think it's also coming back. Most of the "inefficiencies" it got tagged with were relics of the server model at the time, like CGI.
Now many are seeing that mastery of a general-purpose language is better than knowledge of specialized methods in a specialized language.
The first is flexible; the latter is not.
https://en.wikipedia.org/wiki/Haskell_(programming_language)
"Appeared in 1990; 23 years ago"