You don't know Python
Blog - Chahns Blog
Written by Christopher Hahn   
Tuesday, 17 March 2009 12:02

Not long ago I was mutually baited into an argument with one of our developers, in which he challenged me on why I had chosen Python for my most recent project. His claim that I didn't "know Python" he backed up with a few questions:

  1. What is Python's method resolution order?
  2. How does it bind variables on its stack?
  3. Does Python implement closures, and if so, how?

Now, I'll be the first to admit that I don't "know Python". I can express my logic in the Pythonic vernacular, but there's much about it that I don't yet know about or understand. In much the same way as a person unfamiliar with English will use the imperative mood where the subjunctive is called for, it still works, but it's not done in the clearest and most accurate way.

I jokingly retorted that I didn't even know those things about Perl, not because it's true but to make a point. I know Perl (and I know the answers in Python, too). But I don't need to know its MRO, how it "binds variables on its stack", or how to write a closure in it, in order to write good Perl code.

"Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it." -- Alan J. Perlis, "Epigrams in Programming", 1982.

Do you really have to know everything about X in order to "know X"? Do I need to know Python's opcodes and when they're invoked? Do I need to know Perl's SV, HV, and other such structs and the hints maintained therein? Really, half the point of using these interpretted languages is so that you don't need to know their guts.

So at what point do we say that someone "knows a language"? Is it when the person can write something in it that actually works?

print "I know Perl and Python and PHP.";
Or is it really just a matter of being able to write the most easily used (i.e. imported, subclassed) and maintained code? Well, that kind of code usually costs more in terms of conciseness and efficiency.

Is it when someone can effectively employ esoteric parts of the language, like Python's metaclasses, Perl's formats and indirect objects, or English's subjunctive mood? Some might argue that esoteric language features ought not to be used because they reduce semantic transparency, making the expressions more difficult to maintain.

Perhaps "knowing a language" means being aware of those esoteric features, knowing how they work when you encounter them, and knowing what to not do. (On split infinitives, cf. Brown, 1851; Jespersen, 1905; Fowler, 1926; Curme, 1931; and many more.) At first reading, that seems like a good fit to me, but think about it: you couldn't say you knew the language until you were familiar and comfortable with every language feature available.

One of my former co-workers is notorious for writing terrible code. It works, yes, but consider: a Python script that provided singleton classes automatically instantiated which, upon instantiation, directly interacted with global collections which were in turn indexed by global functions that might or might not end up accessing methods of one (and no more than one) of those objects. And that's just the beginning. Or consider his project in which he invoked metaclasses like a crackhead invokes his pipe: as a solution to every problem he didn't want to deal with the right way.

This person knew Python's features. What he didn't know was how to write good Python. The code he wrote is unmaintainable, inextensible, single-use garbage.

There are plenty of examples I could bring up in Perl, Python, and even Bash, but the point is made: knowing a language doesn't mean using its every feature or knowing everything about it. It means being able to understand its less cryptic expressions without assistance; to discover and subsequently understand the meanings in its crypts; and to express oneself according to its grammar in a way that is clear, concise, correct, natural, and appropriate.
"Don't have good ideas if you aren't willing to be responsible for them." -- Alan J. Perlis, "Epigrams in Programming", 1982.



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! Yahoo! Free Joomla PHP extensions, software, information and tutorials.
Comments
Search RSS
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated on Tuesday, 17 March 2009 13:12