Guido van Rossum
๐ค SpeakerAppearances Over Time
Podcast Appearances
We're on a team of a whole bunch of people with maybe a little mind and we can only manage one web connection at a time.
So I'm just sitting looking at this web connection and I'm just blocked until something comes in and then I'm already waiting for it.
I get the data, I process the data, and then I go back to the top and say, no, sort of, I'm waiting for the next packet.
Those are about the two paradigms.
One is a paradigm where there is sort of notionally a thread of control, whether it's an actual operating system thread or more an abstraction.
In asyncio, we call them tasks.
But a task in asyncio or a thread in other contexts is devoted to one thing, and it has logic for all the stages.
Like when it's a web request, wait for the first line of the web request, parse it, because then you know if it's a get or a post or a put or whatever, or an error.
then wait until you have a bunch of lines until there's a blank line, then parse that as headers, and then interpret that, and then wait for the rest of the data to come in if there is any more that you expect, that sort of standard web stuff.
And the other thing is, and there's always endless debate about which approach is more efficient and which approach is more error-prone,
Where I just have a whole bunch of stacks in front of me, and whenever a packet comes in, I sort of look at the number of the packet, that there's some number on the packet, and I say, oh, that packet goes on this pile, and then I can do a little bit, and then sort of that pile provides my context.
And as soon as I'm done with the processing, I sort of... I can forget everything about what's going on because the next packet will come in from some random other client and it's that pile or it's this pile.
And every time a pile is maybe empty or full or whatever the criteria is, I can toss it away or use it for a new space.
But...
Several traditional third-party libraries for asynchronous IO processing in Python chose the model of a callback.
And that's the idea where you have a bunch of different stacks of paper in front of you.
And every time someone gives you a piece, gives you a new sheet, you decide which stack it belongs to.
And that leads to a certain style of spaghetti code that I find sort of aesthetically not pleasing.
And I was sort of never very successful.
And I had heard many stories about people who were also sort of complaining about that style of coding.