[Python-ideas] Making stars optional? (was: Making colons optional?)
Steven D'Aprano
steve at pearwood.info
Sat Feb 7 00:59:18 CET 2009
Georg Brandl wrote:
> Steven D'Aprano schrieb:
>
>> Mathematicians get away with this sort of ambiguity because they are
>> writing for other mathematicians, not for a computer. Because
>> mathematical proofs rely on a sequence of equations, not just a single
>> statement, the ambiguity can be resolved:
>>
>> y = a(b+c) - ac # does this mean a+() or a*() or something else?
>> y = ab + ac - ac # ah, it must have been a*()
>> y = ab
>
> No context is needed to know what a(b+c) means.
Only if you assume that the mathematician didn't make a typo. Any
operator could appear between the a and the bracketed term: you're
deducing the presence of an implied multiplication by the absence of an
operator, which is the convention in mathematics, but it is an unsafe
deduction if you have only a single line in isolation. It only becomes
safe in context because any accidental omission of the operator should
become obvious in the following line(s) of the proof.
I'm not saying this as a criticism of mathematicians. They value brevity
over the increased protection from typos, which is a valid choice to
make. But it is not a choice available to Python, because we have
multi-character variable names, and mathematical expressions stand alone
in Python code, they aren't part of an extended proof.
> In maths,
> you only have single-character variable names (sub-/superscripts
> notwithstanding), so ab always means a*b.
Except in the presence of typos. This is a small risk for
mathematicians, but a large risk for Python programmers. Not because
mathematicians are better typists than Python programmers, but because
there are more opportunities to catch the typo in a mathematical proof
than there are in a program.
--
Steven
More information about the Python-ideas
mailing list