Python and the need for speed

Chris Angelico rosuav at gmail.com
Fri Apr 14 06:56:05 EDT 2017


On Fri, Apr 14, 2017 at 8:42 PM, bartc <bc at freeuk.com> wrote:
>> Classes and decorators are not esoteric. You sound like an old man who
>> complains about this new-fangled "telephone", and how things were so much
>> better when we had messenger boys to deliver messages anywhere in the
>> city.
>
>
> These days I like code to be as simple and obvious as possible. I guess no
> one's going to complain when it is!

Everyone says that, but there's a stark division between two groups of people:

1) Those who think the code should have an obvious concrete meaning -
that you should be able to see exactly what bits get flipped in memory
2) Those who think the code should have an obvious abstract meaning -
that you should be able to see exactly what the programmer intended.

Declarative notations like decorators can beautifully provide the
second, even though they might obscure the first. For example:

@app.route("/hello/<name>")
def greet(name):
    return f"A very warm hello to you too, {name}!"

Nice, clean code that might be found in a Flask application. In
concrete terms, there's a lot going on, but in abstract terms it's
simple: when this kind of URL is requested, return this formatted
string.

I'm of the opinion that the concrete meaning is insignificant, and
your code should clearly portray its abstract meaning. So classes,
decorators, etc, etc, etc are all excellent tools for *improving*
readability.

Of course, if you feel the other way, you're most welcome to write
everything in C.

ChrisA


More information about the Python-list mailing list