Python is awesome

In the last year, I’ve had the pleasure to program substantial amounts in C, C++, Python, Ruby, ASP (VBScript), and PHP. I’ve also used Microsoft Visual C++ and Qt as graphical frameworks.

By far, the most pleasant languages to work in have been Python. I love it for its utter simplicity and flexibility: it can make ordinarily large tasks two lines of code. Do you want to open a binary file and extract packets of little-endian unsigned four byte integers and character arrays? Two lines of code. I kid you not. Do you want to talk to a serial device? Use “import serial”.

XKCD Comic about Python
XKCD Comic about Python

My initial gripe with the language was the use of whitespace to delimit what was meant to be inside a function/loop. Coming from C, which does not care about whitespace, it was a little offputting. But you get used to it, and frankly whitespace, which inherently enforces proper code indentation, makes more sense from a usability standpoint than concluding statements with a semi-colon.

My other gripe with Python proved to be unfounded: speed. Python implementations interprets code – you do not compile it. Not only that, but Python was much more abstracted from the hardware than C, further hindering speed by the extra code it added in the background. As it turns out, computers are so fast these days that such differences really amount to nothing noticeable. I had Python running for real-time applications without a hitch. For most applications, it’s plenty fast.

If you want to create a GUI, Python has three options of note: TkInter, wxPython, and PyQt. Personally, I recommend TkInter. It comes with the Windows Python install, has the most documentation out there, and can pull off some things (ie. invoke a dialog to save a file) in a single line of text. Furthermore, the code is cross-compatible: your GUI code on Windows will work just as well on Linux – without recoding anything. On the downside, like the other frameworks for Python, creating a full-fledged GUI requires a fair amount of code. This is where Python starts to look less like… Python… and more like C++/Qt or C/GTK+.

All in all, Python and its modules are a wonderful asset to quickly and painlessly develop applications.