Earlier quoted context omitted.
I use yield and generators regularly. They just make sense, but I never knew what a coroutine is in an academic sense
This is why you study CS at university before you start work as a programmer. Otherwise you end up being amazed by the basic CS concepts, or worse, you end up reinventing them badly.
The Python yield keyword explained
21–30 of 53 posts
Re: The Python yield keyword explained
#22Earlier quoted context omitted.
Does studying CS at university make people as insufferably grumpy and unhelpful as you?
Come on, I've got a reasonable point here. People post on forums asking these questions which should have been answered during their educations. If civil engineers had a forum site and someone asked "how do I calculate the load a simple beam", people would say, what the fuck are you doing in your job if you don't know that? Who is employing you and why? Where did you go to college? Who was your tutor because next tim…
So assuming that only well-educated programmers can have questions about a programming language is asinine.
My university education didn't cover coroutines either.
Re: The Python yield keyword explained
#23Earlier quoted context omitted.
It's precisely all the help you need to go and look up your notes on coroutines from college. You did go to college didn't you? Or are you an anti-college hipster, suddenly finding the limitations of that approach.
stch - your account has been hell banned, for nearly a whole year.
Re: The Python yield keyword explained
#24Earlier quoted context omitted.
Does studying CS at university make people as insufferably grumpy and unhelpful as you?
Come on, I've got a reasonable point here. People post on forums asking these questions which should have been answered during their educations. If civil engineers had a forum site and someone asked "how do I calculate the load a simple beam", people would say, what the fuck are you doing in your job if you don't know that? Who is employing you and why? Where did you go to college? Who was your tutor because next tim…
And by the way, I'd rather work with fellow programmers who don't know what a coroutine is than with an insufferable elitist like your posts make you out to be.
Re: The Python yield keyword explained
#25Earlier quoted context omitted.
It's precisely all the help you need to go and look up your notes on coroutines from college. You did go to college didn't you? Or are you an anti-college hipster, suddenly finding the limitations of that approach.
stch - your account has been hell banned, for nearly a whole year.
What does that mean/how does it affect me?
It means that only people who have specifically turned "showdead" on can see your posts. No one can reply to you posts directly. Your upvotes do nothing and don't count. But crucially, to you, everything seems completely normal.
And howd that happen?
An administrator decided that your first ever comment didn't fit the tone of this site (which it didn't, but well, you were new), so they decided to instantly and silently ban your account forever. So you have been commenting, for a year, and basically no one has seen your posts. I feel really bad about that and I hate this objectionable practise.
Re: The Python yield keyword explained
#26Earlier quoted context omitted.
I use yield and generators regularly. They just make sense, but I never knew what a coroutine is in an academic sense
This is why you study CS at university before you start work as a programmer. Otherwise you end up being amazed by the basic CS concepts, or worse, you end up reinventing them badly.
Generally curiosity and willingness to learn is worth more.
Re: The Python yield keyword explained
#27Earlier quoted context omitted.
stch - your account has been hell banned, for nearly a whole year.
(replying to myself because I can't reply to stch directly): What does that mean/how does it affect me? It means that only people who have specifically turned "showdead" on can see your posts. No one can reply to you posts directly. Your upvotes do nothing and don't count. But crucially, to you, everything seems completely normal. And howd that happen? An administrator decided that your first ever comment didn't fit…
Re: The Python yield keyword explained
#28Earlier quoted context omitted.
I use yield and generators regularly. They just make sense, but I never knew what a coroutine is in an academic sense
This is why you study CS at university before you start work as a programmer. Otherwise you end up being amazed by the basic CS concepts, or worse, you end up reinventing them badly.
Re: The Python yield keyword explained
#29It's a coroutine. Not exactly revolutionary.
I use yield and generators regularly. They just make sense, but I never knew what a coroutine is in an academic sense
Roughly there are three fundamental control transfer operations: conditional jumps, subroutine calls, and coroutine calls. A subroutine is a slave, the caller is a master. With coroutines, the caller and callee are peers.
Coroutine calling is more fundamental and easier to program, but it isn't available in C.
The theory is about continuations. A continuation is just "the rest of the program". You can think of it as the program counter (PC). Subroutine calling works by passing a continuation to a routine, when the routine is finished it invokes the continuation. This is done by pushing the program counter on the stack, and the subroutine popping it with a return statement.
Coroutines work by exchange of control. When you call a coroutine you give it your current continuation to call when its ready. But also you do not call the coroutine at the beginning. You call it where it last left off: at its last continuation point.
A set of coroutines are usually called fibres. They represent interleaving of control. You can emulate them with pre-emptive threads and locks, but coroutines are synchronous and non-premptive.
Felix and Go both make heavy use of coroutines (called fthreads and goroutines). Iterators as in Python are a special case.
In general on today's badly designed CPU's you have to think of coroutines as requiring stack swapping. Threads do this which is why you can emulate coroutines with threads.
By far the most well known coroutine scheduler is .. the Operating System. Its basically a coroutine of applications. This is why you can read and write to files: the real world is event driven but callbacks are impossible to program with. So the operating control inverts the events by stack swapping so your application can be written as a master.
You think you're calling the OS, and the OS thinks its calling you. You're both masters. That's coroutines.
Python (and Felix) both have yield, but that's a special case. In general the model is reading and writing channels: yielding is just writing the "sole" channel and getting a function result is just reading it. A channel is basically a "place to swap stacks".
Re: The Python yield keyword explained
#30For example:
def createGenerator():
print "aaa"
mygen = createGenerator()
outputs:aaa
Whereas
def createGenerator():
print "aaa"
yield
mygen = createGenerator()
Outputs nothing.