[personal profile] eub
You know PuTTY, the SSH client? I ran across a page by its author, Simon Tatham. It's about coroutines. Now, coroutines are cool, they're sort of like a call/return construct across threads -- read the page, it explains nicely. But his implementation is a flaming hack. It combines preprocessor trickery with Duff's device of all godforsaken constructs, so you've got macros generating various brace-unbalanced fragments of code like this stuff:
    static int i, state = 0;
    switch (state) {
        case 0: /* start of function */
        for (i = 0; i < 10; i++) {
            state = 1; /* so we will come back to "case 1" */
            return i;
            case 1: /* resume control straight after the return */
        }
    }


This coroutine code is in PuTTY. Do you feel soiled yet?

Well. He's got this great quote, anyway:

Any coding standard which insists on syntactic clarity at the expense of algorithmic clarity should be rewritten. If your employer fires you for using this trick, tell them that repeatedly as the security staff drag you out of the building.
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

Eli

April 2017

S M T W T F S
      1
23 45 678
9101112131415
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 26th, 2026 04:19 am
Powered by Dreamwidth Studios