I recently found a “poem” about the philosophies of Python. It pretty well embodies the reasons behind my recently acquired love of Python:
The Zen Of Python
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren’t special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one—and preferably only one—obvious way to do it. Although that way may not be obvious at first unless you’re Dutch. Now is better than never. Although never is often better than right now. If the implementation is hard to explain, it’s a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea – let’s do more of those!
This poem was actually immortalized in Python’s PEP 20, where the abstract reads:
Long time Pythoneer Tim Peters succinctly channels the BDFL’s guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down.
For those who might not be familiar, BDFL stands for Benevolent Dictator For Life, a title which belongs to Guido van Rossum, the creator of Python. PEPs are Python Enhancement Proposals.
Now that we have the lingo out of the way, we can talk about the language itself, and how I was introduced to it.
I had spent a fair number of hours fighting to write shell scripts to handle a few tasks on my web server. After tearing a few handfuls of hair out in frustration, I shot an e-mail to my good friend Andrew, who works as a programmer and sysadmin for a local company. He told me that he avoid shell scripts where possible, writing scripts instead in Perl. I had heard of these so-called scripting languages, Perl, Python, and Ruby being the most prominent in my mind, so I decided to look into them. I did a lot of research into these languages, and eventually settled on Python, primarily because of the principles in the poem above.
These principles just completely jive with my thoughts on programming. Python is designed such that most people that haven’t ever written any Python code can read it and understand what’s going on. Some have referred to Python as executable pseudo-code, and it’s almost true! I found a quote which supports the idea of human-readability in code perfectly:
“Programs must be written for people to read, and only incidentally for machines to execute.”
–Abelson & Sussman, Structure and Interpretation of Computer Programs
This is just one of the many reasons for which I chose Python as the language I would attempt to master. Another was the community – the #python channel on Freenode is almost never quiet – there are always people asking for help with some issue or another, and always people there to answer. I’m sure there are similar communities with Ruby and Perl, but so far I really like the community that comes with Python.
The thing that surprised me as I continued to learn about Python is that it is much more than a scripting language – it is powerfully object-oriented, and even has very powerful GUI toolkits such as Tkinter.
I keep discovering more and more exciting things as I continue to learn about Python, and look forward to leveraging it’s power more in my own personal projects. Now I just need to slowly work at getting it introduced at work…
What’s your language of choice, and why?