Python is DOOMED! Again!
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Jan 22 02:23:25 EST 2015
Ethan Furman wrote:
> On 01/21/2015 08:30 PM, Steven D'Aprano wrote:
>>
>> So what is this unspeakable, nightmarish, cryptic abomination going to
>> look like? Here's an example from PEP 484:
>>
>> def greeting(name: str) -> str:
>> return 'Hello ' + name
>>
>>
>> I don't know about you, but I think anyone who cannot read that and
>> intuit that argument `name` is a string and the return result is also a
>> string
>
> There is nothing inherently intuitive about that syntax.
Strictly speaking, you are correct: the only truly intuitive interface is
the nipple. Nevertheless, we often informally describe something as
"intuitive" when we mean the meaning can be guessed or derived from context.
> The : makes it
> look like a dictionary (but it isn't) and the -> looks like a pointer to
> something (but it isn't).
I think you're over-thinking it from the perspective of a programmer with
lots of experience. Think of it as pseudo-code seen from the perspective of
somebody who doesn't know about dicts and pointers.
Arrows are common symbols for directions, flow of time, and results:
Work hard --> Save $$$ --> Buy a new car!!!
It's not hard to jump to the conclusion that -> introduces the return
result.
As for colons, don't think of "dict", think of "mapping". Colons in this
case map argument name to argument type.
The point isn't that there are no other alternative interpretations
possible, or that annotations are the only syntax imaginable, but that
they're not hard to guess what they mean, and if you can't guess, they're
not hard to learn and remember.
--
Steve
More information about the Python-list
mailing list