aaron maxwell

Why I'm Coding In Python 3

(Hint: It's About Gratitude.)

A programming language is a funny thing. Fundamentally, it's just another tool. As a software engineer, I long ago decided it's important to be facile in a range of languages - having the flexibility and skill to create software leveraging the different strengths of each, in different contexts and environments.

At the same time, a language is more than a tool. It's a medium for expression - not just for code, but for ideas. And this again demonstrates the importance of mastering several. General-purpose programming languages are opinionated, whether their designers intend them to be or not. Their syntax, grammar, and creators' original motivations all influence the idioms, patterns of code, and even the ideas that can be expressed in languages [1]. The experience of working with a range of languages will stretch your mind and expand your skills as a developer.

And this is where we get into a different territory, beyond the technical merits of the language, and its platform, and its library ecosystem. It's about the emotional quality of the language for you; how much, well, fun you have while using it.

This dimension is somewhat independent of language, of course, and in fact probably depends more on (a) the program or system you're implementing, and (b) you. I'm sure you can imagine a few software projects you'd prefer not to be involved with regardless of the implementation language. And I'm sure you can imagine some you'd find exciting no matter what language is used.

Yet the fun, excitement, and personal fulfillment you get from creating as a developer. (I'm assuming you are the kind of programmer who enjoys coding at least somewhat - rather than the kind who's in it strictly for the paycheck.) Remember, a general-purpose programming language - and I'm including its libraries, platform ecosystem, etc. - is a medium for expression of your ideas in the world.

At some level, that medium matters just as much as the choice of paint versus charcoal versus crayon matters for an artist. Because as a professional developer, you are going to spend many of your waking hours writing or staring at code in one language or another.

In my life I've been productive in perhaps a dozen different programming languages. But one has stood out as being the most day to day fun to work with. For me personally, that language has, far and away, been Python.

Stated another way: My adult life has been significantly happier, more joyful even, because Python exists.

(Let's be clear I'm talking about myself, not necessarily anyone else. If you've found a different language you enjoy more, wonderful! I'm sincerely glad for you - keep writing software in it.)

The most amazing thing is that this was all just given to me. I have never contributed significantly to the language; I have not financially supported those who contributed to the language in any way. The Python language was just given to me, as simply and as freely as the air I breathe. Isn't that amazing?

I find that if I focus on what I'm grateful for, even just a little while, an urge starts to well up in me to give back. To somehow pay homage, give thanks, for what I've been given. And for "Pythonistas", that relates to Python 3.

I believe Guido van Rossum, the creator of Python, would like the community to move to the new version. I bet that would make him happy. And that, all by itself, is reason enough for me to put some effort into moving to Python 3.

Of course, what really is needed is to move the community forward. Last year, I gave a talk to about 200 Python enthusiasts in San Francisco about my experiences implementing production software systems in Python 3 (which I've been doing since early 2012). I asked for a show of hands of people who were paid write Python code right now. Unsurprisingly, about three-fourths of the room raised their hand. Then I asked people to keep their hand up if they were being paid to develop in Python 3 specifically. Literally no one besides myself kept their hand up.

So, there's some work to do.

Fortunately, the most powerful way to do this is to start with yourself - your team, your project. And we are at a transition point where the library support for Python 3 is getting really solid, making it easier than ever before.

Are you writing software in Python right now?

  • Whenever you start a new, standalone software project or tool that's implemented in Python, that's the easiest place to try using Python 3. Take the "don't look back" approach, and code it for the most recent stable Py3k release. Odds are good the libraries you need are already on PyPi.
  • If you encounter a necessary opensource library that does not support Py3k, it's often a very reasonable and easy effort to create your own fork and port it over. (Though the necessity is diminishing: In 2013, many important libraries - literally too many to list here - actually have official upstream support for Python 3.) Put your port on github or your website, making it available as a public resource (and simultaneously buffing your resume!)
  • You can consider migrating your existing Python 2 projects. In some cases, this is easier than you might think, especially for smaller projects. A common pain point is with any code that does low-level byte and string processing - networking applications, for example - as you are then forced to deal with the bytes-vs-unicode issue. But for applications not significantly affected by this, I've found simply running 2to3 will often get you most or even all of the way there. Especially if you've been coding to recent versions of python 2 (2.6 or 2.7).
  • You may find different projects are isolated enough that it's fine to have some of then in Python 2, and some in 3. In my startup, the main product - a mobile website SaaS platform - has been 100% Python 3 for a long time; but the marketing website, built on Django, runs on Python 2.7 (though that will be realistic to change very soon). Since the marketing and production functions were entirely separate from an engineering perspective, this never caused any major inconvenience (and literally caused minor inconvenience only once in an 18-month period).

If you are the maintainer of a widely used opensource library, the situation is more difficult; supporting, say, Python 2.5 through 3.3 with a single large codebase is frankly very hard (as the Django devs would be able to tell you, for example). But most of us have opportunities to do something significant that will move ourselves - and hence the community - forward, step by step.

Are you grateful for Python? That you have the opportunity to express yourself and create through this language? If so, let's show our thanks together, by doing what we can to move it forward.

P.S. Guido, if you are reading this, I hope you don't find this too embarrassing. Thanks for creating my favorite programming language!

Footnotes

  1. Consider Java, Javascript, and C. Java's strong, class-based object model makes object-oriented programming straightforward once you learn its syntax. Javascript is a functional language sporting prototype-based inheritance, a vastly different yet equally powerful object model, and requiring completely different code structures. C lacks any syntactic support for objects, only allowing aspects of OOP such as polymorphism and encapsulation to be implemented through slightly opaque code patterns. Yet its strengths in low-level programming make it the only sensible choice of the three for implementing a Linux kernel module, for example.