5 ms·
How I learnt to love Perl
- petercooper 18y agobut these are all superficial next to the damage done by all the absolutely atrocious Perl code out there. The writer argues that Perl's being damaged by bad code examples, but if that were the case, PHP would be the least popular language in the world, no? Perl's troubles are not just because of bad code examples, because the language is poorly constructed (in terms of v5, v6 is a lot better), or because its marketing is poor/non-existent.. but because of all of these things and many other issues beside (especially the difficulty of deployment). These issues are enough to make one jump ship after years of non-resolution. (I was a nearly full-time Perl developer from 1996-2005 - haven't touched it at all in the last few years since I jumped ship to Ruby, so it's not as if I'm hating on the language without having once loved it ;-))
- drwh0 18y agophp became popular because it is easy to install and requires almost no configuration post-install. for ISPs it was a no-brainer compared to the relatively complex mod_perl install
- mikeryan 18y agoI'm not sure this is really true, when PHP started to gain popularity most hosts had a default cgi-bin with perl ready to go. The popularity of PHP has much more to do with ease of use for users then admins.
- mikeryan 18y agoIt also doesn't help that the semantics of Perl leads to some difficult to read code even if it is well written.
- mechanical_fish 18y agoIt's not that Perl examples are unusually bad. It's that Perl's syntax is bad. Really bad. Especially for newbs. Declaring a function in PHP which accepts a scalar, an array and a hash: function foo($bar, $baz, $quux = array('quux' => "default")) { Declaring the same function in Perl: sub foo { my ($bar, @baz, %quux) = @_; Which is already terrible. Worse, despite being relatively intuitive (I've made the mistake of writing this more than once, whenever I forget too much about Perl) it's completely broken. In the words of the Camel book: If you want to pass more than one array or hash into or out of a function and have them maintain their integrity, then you're going to want to use an explicit pass-by-reference. Before you do that, you need to understand references as detailed in Chapter 4. This section may not make much sense to you otherwise. But hey, you can always look at the pictures. Here we see that Perl's syntax isn't just very ugly: It's hopelessly entangled with relatively-advanced concepts like references, and dereferencing, and pass-by-value vs pass-by-reference, and wacky only-in-Perl nonsense like "array context" vs "scalar context". Even PHP can do arguments right. Meanwhile, Perl doesn't even apologize for being a language where you have to learn about pointers before you can walk.
- thwarted 18y agoI'm not sure that example, which doesn't do what it looks like it might do, supports your argument. Because sub foo { my($bar, @baz, %quux) = @_ Is just another way to declare your types: void foo(int bar, void *baz[], hash_t quux) { ... Or in your untyped, dynamic language du jour with my bastardized Hungarian Notation: sub foo(Ibar, Abaz, Hquux) ... However, as you point out, that syntax doesn't work because non-scalars need to be passed as references. Most non-scalar types need to be passed as references in C also (I can't remember which C standard let structs be passed as value), which is perl's heritage.
- mechanical_fish 18y agoYes, if you want to write C this sort of thing is the least of your problems. Perl is certainly simpler and easier to learn than C. I'd also agree that Perl's declaration syntax is simpler than Java's, but what isn't simpler than Java's type system at this point? ;) The simple syntax works in multiple Perl alternatives: PHP and Ruby are the ones I know about. Both languages have intelligent defaults to eliminate the need, in many cases, for newbs to think hard about what they're doing. (By default, PHP passes an array of arguments, by value -- with hidden optimizations to avoid the overhead of excess copying. The PHP argument array may include entire arrays as arguments. Meanwhile, in Ruby everything is an object, so Ruby passes an array of object references.) These are the languages which constitute Perl's competition, today. (Along with Python, of course, which I am unfairly leaving out of my argument because but I don't know how Python handles arguments! But I'm sure the answer is "with reasonable intelligence".)
- nostrademons 18y ago"but what isn't simpler than Java's type system at this point?" Haskell's type system. ;-)
- deleted 18y ago[deleted]
- DavidMcLaughlin 18y ago
- timr 18y agoInteresting that you should complain about Perl, then say that you've moved to Ruby, because in my opinion, Ruby is no better constructed than Perl. The biggest crime I see attributed to Perl -- flexible syntax -- applies to Ruby in spades. (Ruby's actually much worse, since it allows you to do obtuse metaprogramming tricks that would make a good Perl coder blush. Not to mention the fact that it's a LOT slower.) I think the main difference is that Perl is old, and Ruby is new. Geeks are a cantankerous, competitive bunch, and it's harder to be the hot new guy with mad skillz if you're working in a well-established language that has a huge base of expertise and good programmers. As a result, lacking outside pressures, programmers will always migrate to the flavor of the week, so that they can stand out from their competitors.
- lacker 18y agoRuby gets the basics of object oriented programming right. You should not have different syntax for different object types. In Perl, even for things like assigning to a variable or passing an argument to a function you need to know the types. It is nearly impossible to replace a list or a hash table for another datatype later. Ruby gets the simple stuff like this right.
- timr 18y agoRuby's way of doing things is not necessarily "right". It's different. In particular, if your fundamental types are fundamentally different, there's a strong argument that they should have different interfaces. Object-oriented programming does not require that all types be polymorphic, and pretending that they are is a source of confusion.
- drwh0 18y agoall of this kvetching is pointless. if you use and like perl, the statistic you really care about is the activity of CPAN, which continues to thrive. if you like perl and are productive with it, why stop? because some moron on hacker news says perl is "noisy"? if you stop using a tool you like because of a blog post....get used to changing tools often, because "...is dying" is popular with bloggers.
- mechanical_fish 18y agoif you like perl and are productive with it, why stop? To pick a rather extreme example, consider COBOL. COBOL is also not dead (I know people who make a living writing COBOL) but it is a tool which no young programmer wants to learn, unless they have a very specific personality or the money is really, really good. If you don't mind the fact that the talent pool is reportedly shrinking and the price of finding talent is reportedly rising, then you're right: Perl works as well as ever. (And much better than COBOL, of course. Perl will need another thirty to fifty years to reach COBOL's current stage. It's still quite pervasive, especially in its niche.) But if you pine for the glory days of 1995, when exciting new developments in computing were being constructed primarily in your language, you will want to learn a language other than Perl. Or, if you anticipate the need to expand your operation from two or three talented coders to twenty or thirty, you might need a language other than Perl.
- etal 18y agoIsn't git's porcelain mostly Perl and shell scripts? (...which is gradually being rewritten in C, I know.) It does appear that the signal-to-noise ratio in the talent pool declines over time, for just about any popular programming language (other than C, possibly).
- SwellJoe 18y ago"But if you pine for the glory days of 1995, when exciting new developments in computing were being constructed primarily in your language, you will want to learn a language other than Perl." This is exactly the sort of FUD the article seemed to be targeted at. Perl is, currently, a more powerful language than Python or Ruby in several areas. I happen to like all three languages, and have written significant code in Python, but the Perl community is still very active and doing interesting things (as the increase in contributions to CPAN indicates). It's just a more mature community. When someone, say, writes an SMTP server in Perl, they don't freak the fuck out and post a hyperbolic blog post about how freakin' awesome it (and they) are...they merely upload it to CPAN, where it joins the dozen other projects that do the same thing in different ways. If you consider all of the catching up that's happening in the Ruby and Python worlds to be "exciting new developments"--like mature testing frameworks, coverage reporting, library packaging and management, deployment tools, Apache modules, etc.--then, yes, you'd want to be working in a language that doesn't already have excellent implementations of all of those things. Of course, if the Perl community were content with what they currently have, and weren't always pushing forward with newer/better ways to do things, it would be just as bad. But, Moose, as the obvious (but not only) example, should make clear that that's not the case. "Perl will need another thirty to fifty years to reach COBOL's current stage." I hope you'll remember this in two years. If it still seems likely to come true after Perl 6, I'll buy you a beer.
- rkowalick 18y agoInteresting. I did not know that British English uses "learnt" for the word "learned" in American English.
- timr 18y ago"I had always known of it but had shied away from it for so long because, again, it didn’t follow the same rules as my comfortable PHP shared hosting comfort zone." I'm pretty sure that this comment applies to 99.9% of all language complaints I read on the internet. Even smart people have a tendency to bash what they don't understand.
- newt0311 18y agoSo... what happens when this guy finally learns of a well designed language like python? Does his head just explode?
- DavidMcLaughlin 18y agoGood to see you read the article. I already have a VPS set up running django for my band website. Python is great, but Perl is great too.
- jimbokun 18y agoWhat things do you like better about Perl than Python? (honest question)
- DavidMcLaughlin 18y agoI didn't say I liked anything in Perl better than Python. There may be a couple of things, but it would just boil down to personal taste. Conversely, I like Python better than Perl in two major departments though: 1) The way you import stuff in Python. If you have a long namespace in Perl you have to type it out every time you instantiate an object. Example: use Organisation::Project::App::Models::Feature; my $feature = Organisation::Project::App::Models::Feature->new(); In Python you would do: from organisation.project.app.models import feature; feat = feature(); It's a small point, but when you have multiple views/actions inside a controller that all use the same model you start to get annoyed typing that namespace in Perl. 2) The native OOP system in Python is much easier than Perl. With Moose this is far less important than it used to be, but comparing core Perl to core Python it is an issue.
- draegtun 18y agoYes its seems common for Perl libraries in commercial environments to get very long and come a right PITA ;-( However check out the excellent "aliased" module... http://search.cpan.org/dist/aliased/ http://search.cpan.org/dist/aliased/ From its POD... use aliased 'My::Company::Namespace::Customer'; my $cust = Customer->new; use aliased 'My::Company::Namespace::Preferred::Customer' => 'Preferred'; my $pref = Preferred->new;
- scott_s 18y agoI think the lesson of this post is learn to use your tools well, despite how you feel about them.
- xiaoma 18y agoquitting a difficult situation isn’t really in my make up. Neither is humility, judging from this blog post.
- jm4 18y agoI wish the author of this article had learnt to spell...