[Python-Dev] Importance of "async" keyword
Nick Coghlan
ncoghlan at gmail.com
Mon Jul 6 04:05:28 CEST 2015
On 6 July 2015 at 10:49, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Jul 05, 2015 at 11:50:00PM +0200, Sven R. Kunze wrote:
>
>> Seems like we stick to this example once again. So, let me get this
>> straight:
>>
>> 1) I can add, subtract, multiply and divide real numbers.
>> 2) I can add, subtract, multiply and divide complex numbers.
>
> I don't think that this is a complelling analogy for calling regular
> functions and awaitable functions.
I actually really like the analogy, as the "Why can't complex numbers
be just like real numbers?" reaction is pretty common when folks are
first learning to use them for things like signal analysis. I know it
didn't really sink in for me at university - it was only a couple of
years into doing digital signal processing full time that the concepts
involved in switching back and forth between linear real number based
time domain analysis and cyclical complex number based frequency
domain analysis really started to make sense to me.
There's a wonderful page at
http://betterexplained.com/articles/a-visual-intuitive-guide-to-imaginary-numbers/
which not only does a great job of providing a relatively intuitive
explanation of the behaviour of complex numbers as an answer to the
question "What is the square root of negative 1?", it also compares
them to the original reactions to the "absurd" notion of negative
numbers as an answer to the question "What is the result of
subtracting a larger number from a smaller one?".
"Why can't coroutines be just like subroutines?" strikes me as being a
similar case where the answer is "because not everything can be
appropriately modelled as a subroutine", but that answer isn't going
to make intuitive sense if you've never personally encountered the
limits of subroutine based algorithm design.
I also think the analogy helps provide good design guidance, as folks
are already familiar with the notion of "use real numbers if you can,
complex numbers if you need to", and extending that to an attitude of
"use subroutines if you can, coroutines if you need to" would be a
*very* good thing in terms of encouraging maintainable designs.
"Are complex numbers better than real numbers?" is hopefully a
self-evidently nonsensical question - some things are better modelled
as complex numbers, others as real numbers, so the only reasonable
answer is to ask "What are you trying to model?". "Are coroutines
better than subroutines?" is the same kind of question, just applied
to algorithm design rather than numeric modelling.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list