11 votes

Notes on structured concurrency, or: Go statement considered harmful

13 comments

  1. [8]
    Comment deleted by author
    Link
    1. [5]
      unknown user
      Link Parent
      I don't think the author was trying to say that unbounded threads should literally never be used, in the same way that they acknowledge the fact that everything compiles down to goto in the end....

      The title is clickbait, because the author is choosing to ignore that Go is explicitly intended to be a low-level systems programming language. This design goal requires that a primitive like go func() exist, so that higher-level concurrency concepts can be built upon unbounded threads. Go [...] even has that goto statement the author uses as an example of vanquished evil.

      I don't think the author was trying to say that unbounded threads should literally never be used, in the same way that they acknowledge the fact that everything compiles down to goto in the end. (I would also like to mention that Rust is also intended to be a systems programming language, yet it has no goto.)

      4 votes
      1. [2]
        Comment deleted by author
        Link Parent
        1. tan
          Link Parent
          Yeah, that is kind of an incriminating quote. My personal interpretation is that the author is being a bit hyperbolic and is mainly talking about a specific Python use case.

          In this post, I want to convince you that [...] thread spawning and callback registration – should be removed entirely and replaced with nurseries.

          Yeah, that is kind of an incriminating quote. My personal interpretation is that the author is being a bit hyperbolic and is mainly talking about a specific Python use case.

          1 vote
      2. [3]
        teaearlgraycold
        Link Parent
        Is there anything that Go does better than Rust?

        Is there anything that Go does better than Rust?

        1. joelthelion
          Link Parent
          Compilation speed would be one. Also it has a GC, so it's not really comparable. Writing Rust requires more effort.

          Compilation speed would be one. Also it has a GC, so it's not really comparable. Writing Rust requires more effort.

          6 votes
        2. tan
          Link Parent
          As @joelthelion said, they're not really in the same category. I'd say Go's niche is definitely writing network stuff like backend services (and it's pretty badly suited to most other things),...

          As @joelthelion said, they're not really in the same category. I'd say Go's niche is definitely writing network stuff like backend services (and it's pretty badly suited to most other things), whereas Rust is systems programming with modern concepts.

          Of course, you can use either language for very different purposes - I know of GUI apps written in both.

          1 vote
    2. [2]
      joelthelion
      Link Parent
      If go func() is supposed to be a low-level primitive, why does it have such nice syntax?

      If go func() is supposed to be a low-level primitive, why does it have such nice syntax?

      1 vote
      1. [2]
        Comment deleted by author
        Link Parent
        1. joelthelion
          Link Parent
          No, it's not a joke. I didn't comment on the syntax of the go language, but of that particular primitive. You mentioned that it's a low-level construct that should be used to build higher-level...

          No, it's not a joke. I didn't comment on the syntax of the go language, but of that particular primitive. You mentioned that it's a low-level construct that should be used to build higher-level concurrency concepts. In my mind, that means go func() should be used mainly in concurrency libraries. That would suggest it doesn't need prime syntax "real-estate", which could be used for concepts that are actually used often in practice.

          Note that I'm exclusively talking about syntax. In point #2, you seem to be confusing syntax and semantics.

  2. [2]
    joelthelion
    Link
    If you can get past the clickbaity title, this is an interesting read. And the author does make a parallel with goto, so it isn't that clickbaity anyways.

    If you can get past the clickbaity title, this is an interesting read. And the author does make a parallel with goto, so it isn't that clickbaity anyways.

    3 votes
    1. moredhel
      Link Parent
      I agree, I found this a really interesting article which talks about issues I have definitely experienced when writing concurrent code. I've actually been writing a go project for the last few...

      I agree, I found this a really interesting article which talks about issues I have definitely experienced when writing concurrent code. I've actually been writing a go project for the last few months, and have been afraid to use the go primitive as I'm not wanting to have to deal with synchronisation and resource-cleanup.

      2 votes
  3. [2]
    panic
    Link
    This blog has some other posts on async API design that are worth reading as well. In particular, "Some thoughts on asynchronous API design in a post-async/await world" and "Timeouts and...

    This blog has some other posts on async API design that are worth reading as well. In particular, "Some thoughts on asynchronous API design in a post-async/await world" and "Timeouts and cancellation for humans" make a convincing case for this kind of structured concurrency model.

    2 votes
    1. tan
      Link Parent
      Yeah, I really love Trio's blog posts. They've actually convinced me to give it a try next time I want to write something small in async python.

      Yeah, I really love Trio's blog posts. They've actually convinced me to give it a try next time I want to write something small in async python.

  4. Durinthal
    Link
    The title is a reference to the original "Go To Statement Considered Harmful" essay and its follow-ups that copied the phrase, as mentioned down in the details of the post itself.

    The title is a reference to the original "Go To Statement Considered Harmful" essay and its follow-ups that copied the phrase, as mentioned down in the details of the post itself.

    1 vote
  5. b55t
    Link
    Don't channels in go do this exact same thing? You can open channels, close or merge them. So just like the black-box paradigm diagram shows, the control flow sort of 'fans out' and then 'fans in'...

    Don't channels in go do this exact same thing? You can open channels, close or merge them.

    So just like the black-box paradigm diagram shows, the control flow sort of 'fans out' and then 'fans in' again once everything is complete.

    This is trivially done with channels. Wait-groups should also address this issue.

    The author of course has a point. I still find concurrent programs harder to work with than single-threaded non-concurrent ones. At the same time I feel the 'go' statement is only dangerous if used for the sake of it and without considerations for what happens before and after you split off a function.