I Love Perl...and I Hate Perl

Published July 08, 2005
Advertisement
I've worked with Perl for over 10 years now, off and on. At various times, I've made a living at it. In fact, if I had to rank my skills in various languages, it would probably go somethine like this:

Guru: C++, Perl
Expert: Java, SQL, HTML, &#106avascript
Good: DOS, C-Shell, Bourne-Shell
Novice: Lua, Python, Visual Basic, PHP

I can do some pretty amazing things with Perl - it's a wonderful language that is almost without peer in parsing and batch processing. (Lots of people say that Python is better, and from what I can tell, it can do pretty much all that Perl can, but I just have a hard time liking it. it's an aesthetics thing for me - I can't stand the enforced indentation).

Like any other language, though, Perl has it's good and bad points. On the plus side, Perl allows some very rapid development of certain types of applications - text processing, batching, etc. It has a lot of built-in data structures and it's way of handling data is very powerful.

On the down side, there are almost always a number of different ways of writing the same code and if you're not careful, you can write some almost completely unreadable code. Perl is well known for obfuscated code and seems ideal for doing "clever" tricks that are optimized, but take years of practice before being able to understand them or use them wisely. Basically, what I've found is that every Perl programmer seems to have their own unique style, not just in formatting, but in what parts of the language they use to accomplish the same tasks.

As a small example, take the methods for passing parameters to a method. To pass an integer, a string, and 2 arrays to a method, there's a number of different ways that I know of off the top of my head:

&foo( $n, $s, \@a1, \@a2 );sub foo{  my ( $n, $s, $aref1, $aref2 ) = @_;  my @a1 = $$aref1;  my @a2 = $$aref2;}


&foo( $n, $s, \@a1, \@a2 );sub foo{    my( $n, $s ) = ( @_[0], @_[1] );    my @a1 = @{ @_[2] };    my @a2 = @{ @_[3] };}


foo $n, $s, \@a1, \@a2;sub foo( $$@@ ){  my $n = shift;  my $s = shift;  my @a1 = @{ @_[0] };  my @a2 = @{ @_[1] };}


foo $n, $s, @a1, @a2;sub foo2( $$\@\@ ){    my $n = shift;    my $s = shift;    my @a1 = @{ @_[0] };    my @a2 = @{ @_[1] };}


foo( $n, $m, \@a1, \@a2 );sub foo ($$**){    local( $n, $s, *a1, *a2 ) = @_;}


And there's even more ways to do this as well, but I'm not including them all for brevity - I just wanted to illustrate my point.

Ultimately, this flexibility in syntax is both a good and a bad thing - it makes the language very powerful and flexible, but it also makes it virtually unreadable at times and means that everyone is going to get used to doing things in different ways - making other people's Perl code much harder to "translate".

Anyway, there really isn't a lot of point to this entry except to say that I love Perl...and I hate it. This came up, of course, because I've been doing a few "simple" scripts in Perl lately for work. As always happens, the "simple" job turns into a massive behemoth of a job and the scripts to handle it get convoluted, loaded with special-case handlers, etc. Perl allowed me to do some very elegant solutions, but everyone else who's looked at the code has just boggled because it's...well, Perl, and they didn't know Perl could do many of the things I did with it.

The gist: code reviews of Perl are a bitch =)
Previous Entry Tired but Happy
0 likes 1 comments

Comments

Patbert
I love the way you can parse the URL header and then put all the queries after the question mark into an array in one line of code. But after doing an entire web project in perl on a server that had no debugger (if the page loaded it worked, if the page was blank you had made an mistake) I can see the annoying side of perl.
July 12, 2005 07:55 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

What Did I Do?

756 views

What would YOU do?

913 views

GDC 2006

993 views

Layoffs Suck

921 views

From Under My Rock

829 views

Sleep?

760 views

Almost there...

764 views
Advertisement