Python is Great!

I’ve been meaning to set up this blog for quite some time, and finally got around to it one morning at 2AM. :-) I figured I’d start things off right by mentioning one of my all-time favorite programming languages. I started using Python when we, as in my company (Intelesys Corp), began using SCons, a Python-based build environment. I was fascinated by the fact that SCons could do dependency scanning of your source files and avoid having to maintain them in your makefiles, especially when some of the files are auto-generated. We’re now using SCons to build code for 3 different embedded platforms, and have even incorporated some of the weird nuances of the embedded environments. But, it was Python’s power that really enabled us to do that.

These days I find myself incorporating Python into nearly everything I do. I’ve written scripts to help manage source trees, create log message templates, file generation, prototype code, and other miscellaneous things. Then I decided to take a closer look at Trac. It’s a tool that we’ve been using internally for issue tracking, and for a simple project maangement purposes. I was amazed at the cleanliness of the code, and how powerful the tool was given that the core of it resides in a few simple files. One guy helping the project, Christopher Lenz, wrote the core compentent architecture that Trac uses. It’s incredibly flexible, easy-to-use, and most of all: simple. It inspired me to take a much closer look at Python, not as a scripting tool, but as a programming language in it’s own right.

Along my journey, I’ve found that Python is one of the most dynamic programming languages I’ve ever seen. In C++ and Java, you learn that you have to create interface classes to pass things around generically. In Python, they threw that out the door and said, “what you need is to have the right methods in the right place”. What’s important is the object’s behavior and interface, not the name of it’s base class. On top of that, objects can morph in real-time. You can add any attribute you want to an object, at any point time (warning: doing so may result in hard to maintain code). Most recently, I helped develop a Python-based test framework to do long term testing, and protocol verification among other things. It was great to have the ability to write a set of methods, and then have a top-level class pull together everything to push and pull data through the stack automagically. My team can now focus on the nitty-gritty details of the protocols and the commands the device implements. The other stuff, Just Happens. What’s more amazing was how we could incorporate some of Python’s advanced features to make the framework wonderfully easy to use. You can have a new test for your device up and running in minutes, and not have to always focus on the details of how the packet is structured.

I still use Python for other tasks. I most recently wrote a script that will take your Courier-IMAP (or KMail) Maildir store and push out the contents to an IMAP server which doesn’t have a Maildir backend. I didn’t like the other options that I had. imapsync requires that both the our old and new IMAP server be online, and mbsync was just to hard to work with. The latter also didn’t set IMAP’s internal date correctly, so it would appear as though all your messages showed up on the day I did the transfer. Anyways, it only took a couple hundred lines to write a Python script that would parse the directory structure, create the same structure on the IMAP server, and then push all the data over with the internal date and the flags on the emails set correctly.

If you’re looking to pick up a new programming language, I highly recommend Python. It’s quick, it’s fun, and it’s powerful.