"as" keyword woes

Chris Mellon arkanes at gmail.com
Thu Dec 4 11:44:33 EST 2008


On Thu, Dec 4, 2008 at 8:45 AM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Thu, 04 Dec 2008 20:53:38 +1000, James Mills wrote:
>
>> Readability of your code becomes very important especially if you're
>> working with many developers over time.
>>
>> 1. Use sensible meaningful names.
>> 2. Don't use abbreviations.
>
> This is excellent advice, but remember, what is a sensible meaningful
> name is domain-specific. In a maths library, this would be sensible:
>
> def poly(x):
>    return 4*x**3 -2*x**2 +3*x -7
>
> and this ridiculous:
>
> def poly(real_number):
>    return 4*real_number**3 -2*real_number**2 +3*real_number -7
>
>

I actually wonder. The former is "sensible" in a math context because
there's a very long tradition in mathematics of using terse,
inscrutable placeholders for terms. I'm not a mathematician and I
don't know anything about the history of mathematical notation, but
I'd guess this has something to do with the fact that maths has
historically been done with a pencil and paper, and that terseness is
an important quality when you have a limited canvas and lots of stuff
to write.

Aside from the cultural indoctrination, though (and that may be a real
and strong force when dealing with math software, and I don't want to
discount it in general, just for purposes of this discussion) why is
it more sensible to use "x" here instead of "number" or "real" or
"real_number" or something else?



More information about the Python-list mailing list