My Views on Python
Posted on July 15th, 2008 in Python | No Comments »
About a year ago, before I had been properly introduced to Python, I was of the opinion that back-end website programming should be done in PHP, and that applications should be coded in C++. I hadn’t at this stage had any kind of Computing Science or programming tuition, nor had I attempted much more than ‘hobby’ programming. When I arrived at university to study Computer Science, I was told that Python was the language that we were going to be taught in. All I knew about Python was that it could be used for CGI programming, and that it had what I considered to be odd syntax. Anyhow, after it received the whole-hearted endorsement of my lecturers I decided that I wanted learn it properly and see what all the fuss was about. 10 months on I program almost exclusively in Python; using PHP, my former ‘main’ language, makes me feel awkward and limited. Here, I present the reasons why (at least for the jobs it is suited to) Python is now my language of choice.
Syntax
The ‘unconventional’ syntax was one of the main reasons I didn’t look at Python earlier. I was used to languages with C-style syntax (C, C++, PHP, Javascript, etc.). Now, I consider the syntax to be one of the things I regard most highly about Python. Readability is a big issue in computer programming, especially if you are releasing code into the Public domain. I have found Python code to be much more instantly understandable and readable than any other language I have used. The indentation-based code blocks ensure that programmers lay out their code in a readable fashion, and also looks cleaner than C-style languages, which are littered with braces.
The syntax being so simple and so close to natural language makes Python easier to learn for beginners; it’s perfect for teaching the basics of programming to people who have never programmed before. Python still allows you to saturate your code with parentheses and cryptic variable names if that’s what you really like to do, but the basic syntax is much cleaner and certainly no less powerful than that of other languages. I also like Python’s multi-paradigm nature - it may be used as a simple imperative language, as an object-oriented language, or as a functional language.
Standard Library
Python’s ‘batteries included’ philosophy means that it has a rich and powerful standard library. Everything from regular expressions, to web protocol handling (httplib/smtplib etc.), to cryptographic hashing, to database connectivity is included. If something is missing, there will probably already be a third-party library available, which can be found with a simple Google search.
Speed
This may seem like an odd one - I’ve mentioned before that Python is not particularly fast and thus not necessarily suited to computationally expensive tasks; I stick by those claims. However, if you compare Python’s speed to other languages in the same class (‘scripting’ languages such as PHP, Perl, Ruby, etc.), it actually does pretty well. Benchmarks from the Computer Language Benchmark Game website show that Python (just vanilla CPython, not PyPy or CPython+Psyco etc.) generally performs better than PHP and Perl, and knocks Ruby out of the water. Admittedly Lua seems to be faster than Python, but that’s only really used for game scripting. On top of this, Psyco, the fantastic JIT compiler I’ve mentioned in previous posts, can allegedly speed up Python by as much as 100x! If this still isn’t quick enough, functions may be coded in C and compiled and imported as a module, which brings me on to my final topic:
Extensibility
As well as having fantastic standard library, Python is hugely extensible. Extension modules may easily be hand coded in C or C++ to eliminate bottlenecks, or bindings for entire C/C++ libraries can easily be created with SWIG or ctypes. A fantastic example of one such library is PyOpenGL, a Python wrapper around OpenGL, created using ctypes. It allows all the really hard work to be done in C and by the GPU, while allowing the flexibility of Python to used. Python may also be easily embedded in C and C++ applications and used as a scripting language (e.g. 3D software such as Maya).
I don’t think of Python as a perfect language - it isn’t right for every job and I couldn’t see myself only ever using Python, but I find programming in it more satisfying, rewarding and productive than in any of the other languages I’ve used.

