February 24, 2014

Which Programming Language Do You Prefer? Why?

This week’s post isn’t about actual coding. It’s more about programming languages in general. More specifically, this post answers the following three questions:

  1. What do you like about your most often used programming language?
  2. What don’t you like about it, and why?
  3. What paradigms does your language support?

Obviously, the answers are completely subjective. So, let’s begin.

1. What do you like about your most often used programming language?

I like Python. It’s not the only language I code in, but it’s my language of choice for most tasks. There’s a number of reasons for this preference:

  1. Python is expressive. One line of Python can replace whole blocks of code in lower-level languages (e.g. list comprehension).
  2. Python works with a wide range of libraries: computer vision, machine learning, natural language processing, graphs, maths and statistics, graphs and plots… you name it, you’ve got it. Most of the time, the libraries are available from a centralized repository and are only a shell command away.
  3. Python is cross-platform. Run it on Windows, Linux, OS/X. Run it on your smartphone. I’ve even run it on a Sharp Zaurus.
  4. Python is interpreted. No need to compile anything; just run.
  5. Python is easy to read. Its strict indentation rules make writing ugly code significantly harder.
  6. Python is flexible. Want to write procedural code to get results quickly? Sure. Want to abstract complexity away by refactoring your code into classes? Sure, Python supports the object oriented paradigm as well.

There are other reasons why Python is great, but the above pretty much seal the deal for me.

2. What don’t you like about it, and why?

Until recently, I didn’t really have much to say about why I don’t like Python. But then, I saw “Python vs. Ruby: a Battle to the Death”. One of the great points made in the video is:

Python is relatively syntactically inflexible.

In plain English, this means that you can’t extend the Python language itself by adding things like new control statements. This is possible in some other languages, like Ruby. Syntactic flexibility enables more expressive code like RSpec and makes mundane testing code read more like plain English. To summarize, the above video offers the opinion:

Ruby is ugly; Python is beautiful
Nose is ugly; RSpec is beautiful

After playing around with Ruby for a short while, I’m starting to agree.

Another small gripe I have about Python is that you need to keep track of which version of Python you’re working with, since the standard libraries continue to change slowly, even between minor releases. For example, the following code:

import collections
counter = collections.Counter()

will work perfectly fine on my dev machine, which runs Python 2.7, but will crash on a production environment that runs Python 2.6. On top of that, there’s also Python 3, which isn’t backwards compatible with the more commonly used Python 2.

3. What paradigms does your language support?

Python is procedural, imperative and dynamically typed. It supports the object oriented and functional programming paradigms. Function arguments are passed by class references (in newer versions of Python, everything is a class).