(no subject)

May 27, 2008 16:58

I just bumped into Eric S. Raymond's notes on Python while I was searching for addition of ad hoc members in Python classes. He wrote something that caught my attention as being very insightful and something that I can identify with, yet couldn't articulate as well as he:

My second came a couple of hours into the project, when I noticed (allowing for pauses needed to look up new features in Programming Python) I was generating working code nearly as fast as I could type. When I realized this, I was quite startled. An important measure of effort in coding is the frequency with which you write something that doesn't actually match your mental representation of the problem, and have to backtrack on realizing that what you just typed won't actually tell the language to do what you're thinking. An important measure of good language design is how rapidly the percentage of missteps of this kind falls as you gain experience with the language.

When you're writing working code nearly as fast as you can type and your misstep rate is near zero, it generally means you've achieved mastery of the language. But that didn't make sense, because it was still day one and I was regularly pausing to look up new language and library features!

This was my first clue that, in Python, I was actually dealing with an exceptionally good design. Most languages have so much friction and awkwardness built into their design that you learn most of their feature set long before your misstep rate drops anywhere near zero. Python was the first general-purpose language I'd ever used that reversed this process.

And to end this post, here's two more nifty idioms from Python:

# substitute for C's ternary operator (?:)
exp1 if condition else exp2

# swap the values of variables a and b
(a, b) = (b, a)

programming, esr, python

Previous post Next post
Up