Syntactic Sugar Considered Harmful

This is a note for those who think that my code is not Pythonic enough. One of the things I want to do on this blog is to provide programming examples both to illustrate various points, as well as to develop some hand-on projects. My attitudes towards what makes code easy to understand has changed over the years, so I thought I would outline some of them here.

A lot of these ideas came together for me during a conversation with my friend Steve some time ago. We were talking about programming languages, and we both noticed that they often go through a life-cycle. They generally start off very simple, but with some interesting new features. This attracts a following, and then more (perhaps missing) features continue to be added and the language becomes more complex. At some point this complexity just gets to be too much, making it very difficult to work in that language anymore, especially for newcomers. Then a new language comes along, and the process starts all over again.

As Steve and I discussed this, I told him about my experiences with C and C++. Learning C was very simple (except maybe for pointers), and dealing with that code was generally great. When C++ came along, the basic object oriented concepts fit really well with the way I did things anyway, so I took to it easily. New things kept being added to the language, like operator overloading and templates. These seemed great at first, but I started to realize that they were actually making my job harder. At a certain point I decided to avoid most of these features. At times I have met other developers who were doing something similar, and one of them jokingly referred to this approach as C+.

These days I do most of my programming in Python. Conveniently, most of the AI community seems to have converged on Python as their language of choice as well, and so that is the language I plan to use for my examples. However, lately I’ve started noticing a similar complexity problem happening with Python. A number of features have been added to the language that I believe are more likely to make a newcomer’s life harder rather than easier. Some of these features include generators, closures and currying.

Just to be clear, I think all of these features have value in very specific cases, and in those cases I will use them. However, I think it is far too easy to overuse them, and to create confusing code in the process. Therefore, I plan on avoid most Python language constructs created after Python 2.0 or so. Of course, all my code will be Python 3 compliant, and will use the new-style classes.

I suspect that this may mark the beginning of the end for Python. Fortunately it will be many years before that end arrives, and whatever language comes along to unseat Python will probably be a joy to learn.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s