| November 18, 2008 10:13 pm

There are certain times for confessions, and now seems like such a time so … here goes: My name is Rob, and I’m an addict. I am addicted to Matlab. If I didn’t have Matlab, my productivity would go to near-zero. For this reason, like any good junkie, I tolerate its expensive fees, obnoxious quirks and serious limitations. That is, until recently.

Some recent events, however, have forced me to start looking for alternatives. After casting around, speaking to friends and colleagues, I have came up with a number of alternatives. These include the “open-source Matlab”, Octave; a programming language called Ruby; and a language called Python. All of these languages have the benefit of being OpenSource, enjoy the support of strong communities, and are relatively easy to learn. So after careful thought and consideration (okay … so some thought and consideration), I have made a serious decision: I am going to learn Python!

A Manifesto

Like all addicts with a serious habit to kick, you have to start with a commitment. Moreover, as many of my past experiments will attest to, it has to be the type of commitment that you will take seriously. If you fail, it has to hurt! And not just a little kind of hurt, either. I’m talking about the kind of hurt that happens when you fall off a seriously pissed off bucking bull. If there isn’t a risk of being maimed … well … that’s just dull. So, here is my manifesto:

I will learn Python.

It’s public, it’s out there and people know. When motivation is needed, the fear of public humiliation is one of the best motivating factors I am aware of.

The Rationale

With the important bit out of the way, I thought I would share a bit of my (somewhat) rational decision making. In doing so, let’s talk about Python for a bit. Once we do that, then let’s talk about why Python is a really good stand in for Matlab. After addressing those two topics, then I’ll really get to the meat of what I intend to do and expound on the frameworks which might get me there.

But first …

Why Python?

The answer to the first question is very simple: Python is really, really cool. Python offers some enormous benefits with almost no costs (at least none that I have found till now). Here are just a few of its strengths.

  1. Like Matlab, it is a dynamic (or scripting) language.
  2. Like Matlab, it has an enormous number of existing libraries and functions available. Indeed, after a bit of surface scratching, I’ve come to the conclusion that it might have even more libraries and functions available than Matlab does. Put differently: Python comes with batteries included.
  3. Python has some seriously beautiful syntax.

Okay, I know how number three sounds, but it’s true. Unlike Matlab, whose syntax evolved from C and C++ in an evolutionary process that makes evolution from pond-scum seem simple; Python was actually designed, in a very intelligent manner! Consider the following code:

def DoSomething:
if condition == option1:
if condition == option2:

You might notice a few simple things. First, the code lines up. This might seem trivial, but it really simplifies a lot of problems. Greatest among them is an issue known as readability. Let me put it in a slightly different way, have you ever come back to a project after some time and realized that you have no idea what a given piece of code is doing? I certainly have (shudders). This problem is almost nonexistent in Python.

You can actually find things! That’s because python uses indentation to mark sections of code. Everything indented under DoSomething belongs to that function. Everything indented under the condition1 conditional statement belongs there. This make it very easy to locate and understand what a given chunk of code is doing. Unlike in C or C++, or even C#, you don’t need to wrestle with the brackets. If you are a coder, you know what I mean. If you aren’t, they look like this: { }, [ ], ( ), or < >. No matter who you are, the mere sight of these monstrosities should dredge some horrific memory from your childhood.

So what about Matlab?

Okay, so we can agree that Python is a well engineered language, but how does it compare to Matlab. I’ve already mentioned that it has a huge number of libraries. But, so does Matlab. Indeed, with its various toolboxes, Matlab is one of the most comprehensive languages available. Want to connect to a database and query records, there is a Matlab toolbox which can do that. Want to do image processing? Ditto. What about Medical Image Processing? Turns out, there is a wrapper for the Insight Toolkit. Pretty cool, huh?

With its position as the defacto language of computational engineering, you would assume that Matlab has an edge on Python. As I alluded to above, this is simply not so. While Matlab does indeed have a huge number of add-ons, these add-ons are not free. Quite the opposite, actually. You will pay dearly for them. For the image toolkit, this amounts to several hundred dollars (per academic user, I was unable to find the commercial price). In comparison, there are many image processing libraries written in Python. While some of them may require some form of payment, the others are OpenSource. This means that they are probably free, in every sense. Once you find the website for the tool, you likely only need to click on the “Download Now” button. There is no messy business with credit cards. More important than free, as in “free beer,” is the other type of freedom.

OpenSource PR people will call the second freedom, “free as in speech.” While confusing, it is actually a rather simple idea. Namely: you can inspect the source code of the functions which you are using. Have a question on the input of a specific function? Doesn’t discuss it in the documentation? When using a proprietary tool such as Matlab, you have dead-ended. With Python, not so. You can inspect the source code to determine what inputs are needed. Nifty!

Now where?

As you have probably surmised, the geek meter is clear in the red zone. What can I say? OpenSource makes me misty eyed. For the practically inclined, however, you probably don’t care. So, let me conclude with the practicalities. Python is clearly awesome, and free. Yet, like all good things, it is not quite that simple. In this case, however, complexity is bliss. For, you see, there are multiple types of Python. The first is standard old Python. While boring it might be called, but let us settle on the name CPython instead. But there are other Pythons, one is written in Java and called Jython. Jython can use the not only the Python libraries, but the Java libraries as well. While I agree that Java is a great and evil beast, it is also immensely old and powerful. If it can’t be done in Java, it likely cannot be done.

The other Python is called IronPython, and it is special too. In addition to the Python classes, it also has access to … the Microsoft and Mono .Net libraries. If it is written in C#, it can be used be used from IronPython, as a Python class. Now, that is power! So, while I will eventually spend some time with CPython and Jython, I am beginning my journey with IronPython. As with all great undertakings, beginnings are important. So, here is what I’ve tried.

  1. I have purchased a guide. Specifically, I bought Michael Foord’s excellent book, “Iron Python in Action” which is available from Manning. Though it technically hasn’t been published yet, you can get an advance copy through the Early Access Program. While slightly expensive ($49.99), it is money well spent. I will probably post a complete review soon.
  2. I have download the files. You can find the IronPython interpreter and everything else you need to get started at the IronPython Codeplex Website.
  3. I have found a good text editor. There are some fantastic free and OpenSource editors including Notepad2 and NotePad++. I have used and really like EditPadPro. At present, though, I am thoroughly infatuated an editor called e (also called TextMate on Windows). Stupid name, great text editor.
  4. I have started reading the book. Chapters 1 to 3 of “IronPython in Action” are great. The first three chapters start with a fantastic summary of Python and .Net.
  5. I am thoroughly committed! The figure below shows my past experiences in trying to learn to program. It was originally shown to me by a much older (and somewhat wiser), mentor. While it does not make me feel better, it does provide some warning of the stages. Forewarned is forearmed.
    1. Phase 1 : In the beginning, it’s just hard. Ridiculously so, in fact. The texts and available tutorials assume a basic degree of knowledge that I never seem to have. While it is disheartening, this phase eventually passes. It does involve a lot of head butting, unfortunately.
    2. Phase 2 : And … you progress to a state of cluelessness. While still out of the depth, it is possible to make progress. It’s just very difficult.
    3. Phase 3 : But … it gets better, and then it starts becoming fun.
    4. Finally … a state resembling completion arrives.


While I am still (securely) at phase 2, it is starting to get better, which provides hope.

A Word on the Articles

With the groundwork laid, I will close with a word about these writings. It is not my purpose to teach IronPython with this series of article. Rather, I hope to provide a snapshot of what my learning process looks like. To those seeking instruction, you really should get Michael Foord’s book. All you will find here is a fellow (and somewhat foulmouthed) traveler. I still hope you come back though, at a minimum you will find some words on my own personal discoveries.


With that, I start my journey into unknown territory. As I travel, I will share what I learn. I am junkie with a serious habit to kick. This will hopefully provide some entertainment to those around me. In the words of the young and the eternally clueless: This will be fun!


3 Responses to “Learning IronPython – Part 1 – A Halfhearted Manifesto”

[…] Learning IronPython – Part 1 – A Halfhearted ManifestoWith its position as the defacto language of computational engineering, you would assume that Matlab has an edge on Python. As I alluded to above, this is simply not so. While Matlab does indeed have a huge number of add-ons, … […]

[…] Learning IronPython – Part 1 – A Halfhearted ManifestoWith its position as the defacto language of computational engineering, you would assume that Matlab has an edge on Python. As I alluded to above, this is simply not so. While Matlab does indeed have a huge number of add-ons, … […]

Steven Hong wrote a comment on January 13, 2009

Hi Rob,

This is Steven with Manning Publications. Could you shoot me an email? I’d like to use a snippet of this post in our marketing…

Steven Hong
Marketing Coordinator
Manning Publications

Care to comment?