Michiel Mulders
May 18, 2022 ⋅ 7 min read

When to use Rust and when to use Go

Michiel Mulders Michiel loves the Node.js and Go programming languages. A backend/core blockchain developer and avid writer, he's very passionate about blockchain technology.

Recent posts:

Using Rust And Leptos To Build Beautiful Declarative User Interfaces

Using Rust and Leptos to build beautiful, declarative UIs

Leptos is an amazing Rust web frontend framework that makes it easier to build scalable, performant apps with beautiful, declarative UIs.

Eze Sunday
Nov 30, 2023 ⋅ 10 min read
5 Best JavaScript Multi-Dimensional Array Libraries

5 best JavaScript multidimensional array libraries

Learn more about the 5 best JavaScript libraries for dealing with multidimensional arrays, such as ndarray, math.js, and NumJs.

Pascal Akunne
Nov 30, 2023 ⋅ 4 min read
Dom Scandinaro Leader Spotlight

Leader Spotlight: Leading by experience with Dom Scandinaro

We spoke with Dom about his approach to balancing innovation with handling tech debt and to learn how he stays current with technology.

Jessica Srinivas
Nov 30, 2023 ⋅ 6 min read
Vite Adoption Guide Overview Examples And Alternatives

Vite adoption guide: Overview, examples, and alternatives

Vite is a versatile, fast, lightweight build tool with an exceptional DX. Let’s explore when and why you should adopt Vite in your projects.

David Omotayo
Nov 29, 2023 ⋅ 16 min read
View all posts

12 Replies to "When to use Rust and when to use Go"

  1. Your Rust thread example doesn’t spin up 10 threads, which I think was intended. It just runs a for loop in a single thread

  2. You didn’t compare Go very well in the last half of the post, in my opinion. You focused very heavily on how Rust approaches those topics instead of mentioning how Go handles them.

    A pet peeve of mine is also “Golang” is not the name of the language as they state on the site due to the confusion of registering Golang[.]org.

  3. What do you mean by the workd “subprocess” when talking about Go? Do you mean to say that the application will literally fork(…) off a child process? I’ll admit that I’ve never used Go, but that was not my impression of its architecture–I didn’t think that there was even a one-to-one correspondence of invoked goroutines to threads, but instead that it had an M-to-N threading model based on Go’s own implementation of pre-emption inside of its runtime. I would appreciate clarification.

  4. Hi Matt, thanks for your comment and honesty!

    The goal of this post is to provide a high-level overview between both languages for developers who need to decide between both languages. I’ve included some code snippets but don’t want to go into detail for each element. A great resource for looking up all discussed elements in this post is https://gobyexample.com/ 🙌

    Besides that, we’ve updated the post’s title from “Golang” to “Go”. Thanks for notifying us about this! 🙂

  5. Hi Ian, no worries, let me first clarify Goroutines using Go’s documentation (http://golang.org/doc/effective_go.html#goroutines).

    > They’re called goroutines because the existing terms—threads, coroutines, processes, and so on—convey inaccurate connotations. A goroutine has a simple model: it is a function executing concurrently with other goroutines in the same address space. It is lightweight, costing little more than the allocation of stack space. And the stacks start small, so they are cheap, and grow by allocating (and freeing) heap storage as required.

    > Goroutines are multiplexed onto multiple OS threads so if one should block, such as while waiting for I/O, others continue to run. Their design hides many of the complexities of thread creation and management.

    In short, Go multiplexes multiple goroutines into threads. So you are right about to M-to-N threading model. I’ve used the word “subprocess” here losely to make the concept more clear. It’s not 100% accurate. If this is confusing, feel free to ping me @michielmulders -> We want to avoid confusion! 🙂

  6. I think your language got confused between concurrency and parallelism while talking about Go. Go concurrency doesn’t spawn tasks across multiple CPUs, it maximises the single CPU utilisation by running sub processes concurrently (not in parallel)

  7. I get an error on line 7:
    thread::spawn(|| {

    error[E0373]: closure may outlive the current function, but it borrows `i`, which is owned by the current function

    Fortunately the Rust compiler tells me how to fix it:

    help: to force the closure to take ownership of `i` (and any other referenced variables), use the `move` keyword
    thread::spawn(move || {

Leave a Reply