Monday, October 04, 2010

Perl

I've spent some time at work finally learning Perl.  When I first looked at the language back in college, I was turned off immediately.  Now I understand what the problem was, and it is the same reason why the language has such a strong following. Perl's basic features and syntax are safe and straightforward.  A Java programmer can look at it and have a decent idea as to what's going on.  But Perl is also incredibly flexible.  If you want to do something, you can probably do it several different ways.  You can make a Perl program easy to read, or fast, or compact - whatever your tastes are as a programmer, the language will accommodate. This is what makes it so well loved, but it can also make it difficult to learn without the proper materials.

I also think there's another, more subtle psychological element to the way Perl works. To me, it strikes a happy middle ground between the various schools of thought about how a language should behave.  A few days after writing that last sentence, I came across a Perl book containing the closest thing the language has to a motto:  "Simple things should be simple, difficult things should be possible".

I guess I wasn't that far off. I think that is a great way to explain Perl.  There is an incredible amount of different ways to use the language, but you don't have to use any of them if you don't want, or more likely, don't need to.  And if you want to stick with the basics, there's no penalty.  It's refreshing to see a programming language that isn't trying to shove a religion-like belief system down your throat.  It can be frustrating to see object oriented languages which are so obsessed with making everything into a class that the simple act of opening a file requires six import statements and a method call that looks like

We.Don't.Want.You.To.Get.Any.Work.Done.FileReader.FileBuffer.LayeredBuffer.LayeredNachos.OpenStream(AndYouThoughtTheArgumentListWouldBeSmall);

On the other hand, there are a lot of small, fast functional languages that decide that you need a million data types, each of which uses every brace and bracket on the keyboard for different results.  Apparently, it isn't enough to have arrays. You also need lists (also nice), tuples (wtf?), and god knows what else.  And if you ever read the documentation for these things, they make it sound as if every exception and difference makes perfect sense.  Back in college, my friend Joe and I were frustrated with the fact that every time we asked what a certain concept was in our Hardware Engineering course, the answer was always "oh, it's just a 4-to-1 Mux", as if either of us knew what the hell that was at the time.  That's what these "whizbang" little languages remind me of (though to be honest, we should have known what a multiplexer was back then).

There's another great quote from the Perl book, paraphrased here - "you can do just about anything you need with a hash".  Amen to that.

PS - the crack at OO Languages above is more due to my time with .NET languages.  Say what you will about Java, but it lets you get to core classes very quickly.

No comments: