Mandatory Perl/Python

I’ve contended that a good computer science degree should focus primarily on science and algorithms, and only secondarily on specific languages and tools. I’d like to modify my position: hands-on experience with at least one scripting language should be mandatory.

Here’s why: students are invariably required to learn one low level language, C/C++ or these days Java. These languages bring with them a set of assumptions that get baked into the student’s impressionable young mind: Strong typing. Specific (as opposed to generic) data structures. Complied code.

The students then take the computer languages course and learn about all the crazy alternatives people tried along the way: Lisp, prolog, fortran, etc. Bad ideas fallen by the wayside.

Thus the students will graduate with a bias toward low level, compiled, strongly typed languages. Not just because that’s the only thing they know, but also because they’re led to believe this is the Right Way.

Now good programmers are lazy. They’ll find scripting by themselves because it’s faster and easier, makes them better programmers, significantly more productive.

Lately, however, I’ve come to notice just how many smart young programmers don’t know scripting. It’s been quite a suprise.

So I chatted with a few of them.

Part of it is just momentum: I know Java, it works fine, why do I need to learn another language?

But the other part, the harmful part, is the unexamined assumption that scripting languages are less capable, less powerful, less “enterprise”, less Good.

The typical first response I’ll get is, “but scripting languages are not strongly typed. Who’ll catch my type casting errors?”

Ok, let’s examine that. Do you really make type casting errors? Really? If you’ve been doing this for even a little while, your programming muscle memory is trained not to make those mistakes.

The real point is that type information is not enough to be a useful error catching tool. Most of your effort will go into understanding what the required argument is. Not its type, but what are valid values. It’s the semantics, not the type. If I told you the second argument of some function is a string you’d be able to compile against it, but you’d have to know what that string represents to do anything useful. Semantics.

On the other hand, look at how much easier life is with duck typing. If the programming language assumes you’re smart instead of trying to protect you against your own stupidity, and if you’re actually smart, you can get things done a lot faster. And if you’re stupid strong typing isn’t going to help you anyway.

The best way to get convinced of the power of duck typing is to try it. Write some scripting code. It won’t take long to feel the power of the handcuffs coming off your hands.

Another strength of scripting is the generic data structure: everything is a hash table.

Turns out you can represent the vast majority of useful things as hash tables. Because you can put arrays, other hash tables, anything you want into those hash tables.

There’s a discipline of mind that comes from thinking of everything as a hash. I’ve found this is the polar opposite of the RDBMS fiends. Sure, you can throw anything into a database, but do you really need to? How about a hash? Did you try the hash? It’s free. It’s fast. It’s part of the language. How ’bout that hash table? Did you realize a hash provides a natural partitioning of you data in case you need to scale beyond one box? Did you know a hash doesn’t require a DBA?

Then you have the compile assumption. Nobody actually likes compiling, but without scripting people assume it’s a fact of life. It’s not. Scripting languages just run. No compile. Say goodbye to your makefile. Squash that ant.

But scripting is not enterprise! It’s not maintainable! It’s slow! It’s for small minded people who couldn’t be bothered to learn a Proper Programming Language!

Scripting is enterprise my friends. Much of the backbone of business is written in Perl. Each time you do a credit card transaction chances are high a piece of Perl code gets tickled along the way. When you search for airline reservations you’re touching scripting. It’s everywhere. I’ll claim (without actual proof) that a lot more of the “enterprise” runs on scripting (usually Perl) than on Java. The rest of it is mainframe.

The maintainability knock, on the other hand, is deserved. There’s a lot of ugly Perl code out there. The obfuscated Perl contest doesn’t help.

Yes, you can definitely write ugly code in Perl. Most people do.

But you can also not write ugly code. Just don’t do the ugly stuff. Write it so that a C programmer can understand it. Don’t allow the fancy ugly stuff. You CAN do this with style guides and rules.

Or just use Python. It’s pretty. It’s well indented. Heck, it’s even object oriented. Ooooh.

Maintainability comes from good design and from having few lines of code. Good design can be applied to scripting languages as well as it can to low level. Scripting has the advantage in lines of code.

But scripting language are so slow. They just won’t scale.

There are applications that require raw speed. No doubt about it. Write those in C. If you’re thinking of writing them in Java, realize that you can get comparable or better speed with a moderm scripting language.

Real speed comes from the design of your algorithm. The next concern is typically scalability: can I throw more boxes at it and have it go faster? Both of these have little to do with the choice of your programming language.

Let’s drag good old 80/20 out of the close for this next part. Most programs spend most of their time in a couple of tight loops. If you optimize those loops your program goes a lot faster.

The thing to realize is that scripting is setup perfectly to allow this optimization. Write your program, find the 80% loop, and rewrite just that part in C. It’s quite easy to wrap C/C++ and expose it as a command in a scripting language. Now you have a program in a high level language that’s also blazingly fast.

That’s not the speed to worry about anyway. These days the speed of writing the application is the real key. If you can get your application to market faster than the competition, enhance it faster, add features faster, you win. Scripting wins here hands down. There are studies out there, but I suggest you try it. Pick a sample app. Write it in Java and time how long it takes. Now pick up a book on Python. Go ahead: start your timer, drive to the store, pick up the book, come back, grab a sandwich, have a nice read. Now write it in Python. Stop the timer. It still took less time than doing it in Java.

But scripting? That’s so below me. I’m very smart. Any idiot can do scripting. I’m a Java guy.

Right.

Being a 10x programmer is about producing good apps fast. A tool that doesn’t hinder good design and gets you there faster is a good tool. Some of smartest people out there use even goofier languages like Lisp. Don’t be afraid. You don’t get to be Enterprise because some marketing guy told you this is Java Enterprise Edition.

Everyone I know who’s actually tried scripting ends up using it. Not necessarily for most of what they do, but at least for some of what they do. There’s nothing to be afraid of. It’s an excellent tool in your arsenal. It challenges some of your assumptions. It teaches you different ways of thinking. It’s a good thing. Go learn one. I don’t care which one; Python is the one I’d recommend right now, but do Perl if you like, Ruby if you prefer, or even Tcl if you’re old skool. But definitely go learn one.

3 Comments so far

  1. Ardee Aram on January 11th, 2006

    Amen to that!

    I am Ardee, a student of the University of the Philippines. Currently, the main programming language that is taught to us is Java. And now, I am doing my undergrad project to graduate and they *require* me to do my web application project in Java (J2EE). How do you like that?

    I like Python more. It’s fast and furious (development-wise and run-time wise). I don’t know why the University has some odd fetish over Java…

  2. Andrew Kurinny on August 4th, 2007

    Agree. In school I studied Pascal and C. Now I have my day job in C# .NET, but everything I write for myself is Python/Django. I hate it, when I need to write something in ASP.NET.

  3. ZoontF on October 12th, 2007

    I agree with pretty much everything except that languages other than C++ and Java are useless and bad ideas. Many esoteric and/or older languages are still in use.

    If you want to work close to the machine AND be efficient, then you better now ASM for your hardware, and the more general case of how to write ASM in the first place.

    If you want to go into scientific modeling, you must know Fortran. No question. Cobol wouldn’t hurt either.

    You’d be surprised at the places SmallTalk will show up.

    How about Objective C? With the re-emergence of OpenStep (i.e. Mac OS X), this old language that gets a lot of punch from its SmallTalkiness sure is turning out to be useful.

    I’m not saying these languages should be taught in school necessarily. But, they all have their places.

    Scripting Languages should be introduced much later in the CSC curiculum. A good programmer needs to know how to create the data structures from scratch that many scripting languages just give you… because you never know when you’ll be stuck with some language that doesn’t have a full-fledged hash table (like VB6), or directed graph, or whatever. You may never use it, but at least you know how to build your data structures.

    Likewise, learning the similarities between languages is key, so you can move from one to another with less effort.

Leave a Reply