135 points · by Mithaldu · 15y ago · 129 comments
To be perfectly honest myself, the last time I looked at Perl was about 4 years ago, and I despised the experience. I used it for about 10 months because the company I worked at had their entire infrastructure running on it, but it was the worst code I had ever seen, so I quit. If I remember correctly the code that broke the camel's back for me (pun intended) was:
$a = $src[$src];
I've forgotten my Perl syntax so the syntax may be incorrect, but essentially what happened was that the original author had defined two different variables with the name "src", one being a scalar variable and the other being an array, and apparently those have two different namespaces.
So when I looked at the perl tutorial that the author points out, it looked like regular perl to me. However, if the syntax of Perl has changed since 2007, then I'd be willing to give it a shot. Although I've recently started learning Python, and I'm enjoying it, except for the dynamic typing and the GIL... which is a rant for another time.
I remember being offered to choose any toolset I wanted for a particular project and finding out that Perl was the only scripting language that had the bindings to the C libraries I needed to use. Naturally, I decided to to do the whole project in straight C instead. :)
The funny thing is, whenever I would code in Perl for a while, I would actually grow acclimated to it. I would start to think to myself, "Hey! I'm finally getting things done. I CAN be productive in this language!" It was only after switching away to another language again that I would re-recognize just how painful Perl really is. This experience actually repeated itself multiple times for me as I moved on and off Perl projects and it helped me learn to sympathize more with others who are perfectly content to code in Perl for a living.
At one point, I had enough and began recording all the weird Perlisms that were wasting my time as I encountered them. My goal was to compile a "95 theses against Perl" document and post it on my manager's door as a joke. Fortunately, I only got into the 40s before my manager offered to let me move to another team where I never had to write a line of Perl again in that job!
It's possible to write good Perl just like it's possible to write good COBOL, and better tutorials would definitely help newcomers to the language do just that. I would rather spend my time writing good code in other languages, however.
I don't think it's the language's fault that poor code exists to teach people the way to Perl zen. It's more that scripting languages themselves lend to one-offs and poor code writing, especially in the days of early Perl, when people were giddy to get their hands on something that wasn't as ugly as "sh". We need better programmers who are not "too busy to write good code" as well as better material.
One of perl's big "natural language" claims is that things mean something different in different context. I think there are several movies based on what can happen when two people have a conversation but have a context mismatch.
Perl Medic (Peter J. Scott) - http://amzn.com/0201795264 Effective Perl Programming (Joseph N. Hall, Joshua A. McAdams, brian d foy) - http://amzn.com/0321496949
Besides those, having a good reference to the language is also essential. For example, I keep Perl In a Nutshell close by, even though I almost always just search http://perldoc.perl.org/ when I need that info.
In the company I worked for that used Perl extensively, there were coding standards. In fact, you don't even need that, you just need to remind everyone that cleverness is not a goal in writing maintainable software, even if cleverness is what Perl's best at.
The reason that an array subscript is "$foo[0]" is because the $ sigil means "HEY COMPILER, the expression here is going to evaluate to some scalar".
@foo is the entire list and the compiler treats it as a list type; $foo[0] is an element of the list and needs storage/behavior of a scalar. Same thing for hashes: %bar is the whole hash; $bar{quux} is an element and must be treated by the compiler as a scalar.
The programmer must remember that square braces mean array subscript and curly braces mean hash lookup.
So basically, this is a compiler optimization implemented by having the programmer provide hints to the compiler. It's overhead that probably isn't needed in the modern age, but we're effectively stuck with it. It wouldn't be so bad if they hadn't made the second (and IMO worse) decision:
You can reuse symbols across contexts. The way this works is that the compiler maintains a symbol table where each symbol has a slot available for each of the types (scalar $, array @, hash %, subroutine &). This was originally the way to emulate pass-by-reference: you'd write a subroutine that assigned its arguments into typeglobs (* foo — think of it as a wildcard for all things named foo that behaves as a magic scalar with the contents of foo's symbol table entry) and then pulled them back out as the types it wanted:
local(*foo) = @_;
foreach $bar (@foo) {
do_something($bar);
}
This amounts to telling the compiler "I want to alias the name foo in all contexts to my argument, and then go look at what's stored in the array at that name" and is a poor man's pass-by-reference.Perl 5 has a real reference system that completely obviates the need for this, except for the case of monkey-patching a subroutine, where you still say:
local *Package::quux = sub { ... }"
What's left is an unfortunate case where things like the GP mentioned ($bar = $foo[$foo]) are possible, and people who think they're being clever will do these things. Like the parent said, this is not a good thing to do.I'm not entirely sure that's correct. I think Larry Wall (being a linguist originally) designed it that way because he thought that using context-sensitive sigils was more like regular speech where leading words indicate the number, i.e. 'a cup' vs. 'some cups'...
use v5.10;
use strict;
use warnings;
my $ref = ['one', 2, 3];
say $ref;
foreach (@{$ref}) {
say;
}
# These are the same. The first form is much cleaner.
# It also makes more sense semanticaly
say @{$ref}->[0];
say @{$ref}[0];
say $ref->[0]; say @{$ref}->[0];
This raises a deprecation warning for me. say @{$ref}[0];
This is technically correct, as the leading sigil "@" indicates you are returning an array, but since you're only returning one element in that array, this should probably be "${$ref}[0]" which returns a scalar only. say $ref->[0];
This the only form which I would consider correct or "clean".This example proves nothing about Perl's power, though. The fact that difficult and fiddly reference handling shenanigans are necessary to handle something as trivial as nested arrays and hashes shows quite the opposite.
Compared to what? C? In what way is it more powerful than Ruby, Python, Ocaml, Haskell, etc.?
There are things perl has over e.g. python (lambdas) but there are at least as many things those languages have over perl (e.g. python generators built in) and all of those languages are easier to use. Look at the code you wrote there! I assume "use v5.10" is actually a forward compatibility declaration instead of a backward one, right? Really embarrassing if so.
The most feature-complete implementation - Rakudo on Parrot - is not production-ready, though, and currently somewhat stalled due to low bus factor: The object-system refactor (which made things like natively-typed attributes possible) introduced a lot of regressions, and the regex engine in particular is not yet fixed as the lead-developer was hit by real-life issues.
Newer languages have warts, too, you just don't know what they are, yet.
The real problem is that "relevance" for technical resources has a very different meaning from "relevance" on the Internet at large, because the content pages and incoming links, by themselves, don't contain all the necessary information to judge whether a page is still relevant. As a result, Google is in some ways less and less useful as a programmer's tool - not because Google is getting worse, but because there are more and more layers of obsolete information out there.
This is bloody brilliant.
But news worthy events are only one form of white out, historical weight is another (as the perl example shows).
Disclaimer I work at blekko.com (a search engine) which allows you to specify things like /date=2005 in the search providing semantic intent. Searching through white-out situations is one of the uses of the slashtag system.
Finding information on Steve Jobs from 2000 - 2005 is actually pretty easy on Google. Search "steve jobs", then on the left-hand bar, click "custom range," and input 2000 to 2005. Done.
I invite readers to actually try the blekko example to see how incapable it is. Searching with /date=2005 : (a) sorts the results by date, such that you the first few pages are full of irrelevant pages from Dec 31, 2005. And, (b) only returns results from 2005 (it's not clear how to search over a time range).
I suspect Google uses more or less the same algorithm for general content and for tech documentation. The difference is, general content - news, discussions, fiction, etc. - rarely loses relevancy, it can only be supplanted by newer, more relevant content over time.
This happens for documentation, but it takes time - and at any given time you end up with a hodgepodge of content for various versions.
There's also no foolproof way to search for content for a specific version - this would go a long way towards fixing the problem. The closest solution is restricting the search results by date, I often have to do that.
http://www.onyxneon.com/books/modern_perl/
Unfortunately you can't create your own set of tutorials from it, and it doesn't rank highly in Google.
http://www.modernperlbooks.com/mt/2011/09/how-to-learn-perl....
One of the problems is Google won't let you filter for tutorials from last, say 2 years. There's lots of solid tutorials for 5.10 and up
The problem is that people looking for a basic Perl tutorial may not know about all the filtering options.
What people should search for is immaterial. For us in the perl community, only what people do search for counts.
Not only should advocating link rot as the preferred solution alarm any web user, but there are people out there who specifically need to learn Perl 4 to maintain or port crappy old systems (they might even outnumber people selecting Perl 6 or 5 for new projects), and we shouldn't throw their tutorials down the memory hole to make the language look more sane. Stick with a notice that better dialects are available, please.
On the larger subject, I agree, old documentation shouldn't be discarded, but should be clearly marked as referring to an older version. Of course, the horrible outdated examples the original article mentions have such disclaimers, but people still see their code as representative Perl code.
Most criticisms I read focus on how dealing with legacy Perl is typically bad because it was written poorly. The thing is, I've read legacy PHP, legacy Python, and other "legacy" code that was just as terrible.
The new Perl code I work with, though, written by my colleagues, is every bit as elegant and readable as code in any other language - provided thoughtful people are writing it.
Perl has a bad rep but I have yet to see a single legitimate argument thrown at it which doesn't boil down to "I read some bad legacy code." I've been in the same boat, and believe me, I sympathize :)
Lots of 15-year-old code is out there on the internet for folks to sneer at.
So as weird as it sounds, Google shares the blame for the poor perl code being written.
If you are really worried about this, write a blog post (or several) that show people how to properly code Perl.
Try searching for information about an obscure problem with (say) Linux. The pages found often relate to earlier versions of the OS and even in some cases 2.4.xx kernels. You have to know a bit to be able to filter the search for newer releases.
Also, more importantly, this task is so huge that a single person trying to solve it on their own is doomed. It needs to be a community thing.
It will take time, but the community will start to change, and thus actually change what users are searching for.
Think of HTML/CSS. One gets a more relevant set of results by searching HTML5, because there was a great deal of effort put into explaining how the language had changed. When looking for bleeding-edge features, a search for CSS3 is more helpful than a search on CSS (which like the perl situation, sometimes returns legacy garbage). The same applies when trying to troubleshoot a problem on OS X: adding 'lion' to the query often improves relevance of results.
I short, make a conscious effort to create a new label and inject it into the public consciousness.
My point was that OP complains they can't change what users are searching for. I assert they can, but they have to change the way they market and talk about their language. They need to present it as markedly different and give users a way to differentiate it in search from previous versions.
(Aside: I don't use Perl. I don't want to use Perl. The things I need to get done I can accomplish in other languages, and that are clear when I look at the code six months later.)
The other side is hacked together scripts. Which have their place, but are often a mess.
There is the CPAN, which is obviously what it is;
And there is the DarkPAN, a term describing all the internal projects in companies, or small tools hacked together by people who don't know or care about the CPAN.
In some parts, the latter is referred to as BedPAN.
(Just kidding, I'm sure you have generous helpings of both :)