Rust VS Go, which language should developers choose in 2023?

Source: InfoQ

In 2023, we have a thousand reasons to learn Rust.

On August 7, the Rust Foundation released the results of the 2022 Rust Survey Report. The report shows that the adoption rate of Rust continues to increase. More than 90% of the survey respondents indicated that they are Rust users; Rust is used for the majority of coding work in , a significant increase of 51.8% over the previous year.

There is no doubt that Rust is increasingly becoming the focus of developers with its excellent memory safety and concurrency performance. However, it is also difficult to ignore Go, a relatively "veteran" player who was once selected as the programming language of the year.

Born in 2009, the Go language has attracted great attention since its unique concurrency model and powerful performance advantages. It is worth noting that, like the Rust language, the creator of the Go language also "hates" C++, and Go is also the dominant language of cloud native.

In the Stack Overflow 2022 developer survey, among the 70,000 responses to the question of "a programming language that makes people love and hate", programmers obviously prefer Rust, 86% of them said they like Rust, and 64% said they like Go. Facing the hot status of Rust, some developers have asked their souls: Is Go still worth learning in 2023?

Rust VS Go, which language should developers choose in 2023?

Rust VS Go, which language should developers choose in 2023?

In addition, in the past two days, whether to choose Rust or Go has also become a hot topic on Hacker News:

Rust VS Go, which language should developers choose in 2023?

A netizen who supports Rust said: "I have also been troubled by this choice for a long time. In the end, Rust won. First, I feel that Rust is closer to the things of the previous Pascal era, and you can control everything; second, if wasm and related technologies are big outbreak, Rust would be a safer choice; then, we already have Python for rapid development, so it makes sense to choose something a little more extreme, and Go is somewhat in the middle ground. Finally, Rust should be used for Core and high-profile, so it is unlikely to be eliminated."

Another developer who disagreed said, "I have been developing in Go for almost ten years, but recently I also tried Rust. I think there is currently some mandatory and misleading preference for Rust, from my experience in From experience at various startups, including my current one, Go is by far the best choice for backend development! Note, performance, functionality or otherwise...the two languages are very, very similar! "

I have to say that both Go and Rust are definitely excellent programming languages. They're modern, powerful, versatile, and deliver great performance. But it really doesn't make sense to directly compare Go and Rust, who is better, because each programming language represents a series of deep trade-offs behind it. Different languages will be optimized for different needs, so when we choose a language, we should also consider what kind of problems we want to use it to solve. So we will start from the applicable scenarios of Go and Rust languages, and discuss the "way" of Go and Rust's design.

While Rust and Go differ greatly in syntax and style, both are first-class tools for building software. Let's start the specific analysis below.

Go vs. Rust: Similarities

Rust and Go have a lot in common, which is why people often compare the two. What goals do they have in common?

Rust is a low-level statically typed multi-paradigm programming language with more focus on safety and performance.

—Gints Dreimanis

and:

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

—golang.org

Memory Safety

Both Go and Rust are among the modern programming languages that place emphasis on memory safety. Over the decades of development of older languages like C and C++, it has become clear that one of the core causes of errors and bugs is unsafe/incorrect access to memory.

So Rust and Go each gave different solutions, but the goal of both is to be smarter and safer in terms of memory management, and to help developers write correct programs with excellent performance.

Fast, compact executable

Both are compiled languages, which means that programs can be translated directly into executable machine code, so that programs can be deployed as a single binary file. Unlike interpreted languages like Python and Ruby, we don't need to ship an interpreter and a lot of libraries/dependencies with the program. As a direct reflection of this core strength, Rust and Go programs tend to run faster than interpreted languages.

General Purpose Language

Both Rust and Go are powerful and extensible general-purpose programming languages that you can use to develop all kinds of modern software—from web applications to distributed microservices, embedded microcontrollers, mobile applications, and more. **Both have excellent standard libraries and thriving third-party ecosystems, plus strong commercial support and a large user base. **Both have been around for years and will continue to thrive in the years to come. Learning Go or Rust would be a very reasonable investment of time and energy these days.

Pragmatic programming style

Neither are overly functional languages (such as Scala or Elixir), nor are they fully object-oriented (such as Java and C#). On the contrary, although both Go and Rust have the functions of functional and object-oriented programming, they always emphasize the pragmatic orientation-that is, solve the problem in the most appropriate way, rather than forcing everyone to use a specific method through "ideology". way to do things. **But if you really like the functional programming style, there are more related tool options on the Rust side, which is one of the advantages of Rust over Go. **

We can certainly argue about what constitutes a truly "object-oriented" language. But to be fair, the style of object-oriented programming that users of C++, Java, or C# expect doesn't really exist in Go or Rust.

—Jack Mott

Massive Development

Both Rust and Go provide many useful features for large-scale programming, so they can both adapt to the real-world needs of large development teams and large code bases. **For example, C programmers have debated for years about where to put parentheses, and whether code should be indented with tabs or spaces; but Rust and Go already use standard formatting tools (Go has gofmt, Rust It is rustfmt) completely solve these problems. They automatically rewrite your code using a conforming style.

It's not that this particular format is subtle, but **Rust and Go programmers are more pragmatic and would rather choose a uniform standard of implementation. **

gofmt's style may not be everyone's favorite, but gofmt has something for everyone.

—Rob Pike

Another big advantage of these two languages is reflected in the build pipeline. Both have excellent, built-in, and performant standard build and dependency management tools. This means that programmers don't have to contend with complex third-party build systems, nor do they need to learn a new system every few years.

I used Java and Ruby early in my career, so writing Go and Rust code has always been a bit intimidating and out of my control. But when I got into Google and saw a service written in Go, I was really relieved because I found it easy to build and run.

The same goes for Rust. Although I've only done research on small scale projects, I can see its ease of use. I wish those infinitely configurable build systems would be a thing of the past, now that new languages come with their own dedicated build tools that work out of the box, isn't that good?

—Sam Rose

**Rust or Go? **

After talking about so many issues, and the fact that both languages are so well-designed and powerful, is there any result in this competition? Or, since both are excellent options, why are people still outraged on social media, writing long commentary blog posts saying "Rust is for idiots" or "Go is not a programming language at all" Kind of harsh words?

Of course, some people just want to vent their emotions, but this obviously does not help to solve the actual problem. At least when it comes to which language to use in a project, or which language to use to break into the programming world, loud voices obviously don't help make the right choice.

Let's go back to the discussion of adults and see how Rust and Go have strengths and weaknesses under rational analysis.

Go vs. Rust: Performance

As mentioned earlier, programs generated by Go and Rust are both fast because they are compiled to native machine code without going through an interpreter or a virtual machine. But Rust's performance is still better, even comparable to C and C++, which are known as the industry's performance benchmarks. And unlike these old-fashioned languages, Rust also provides memory safety and concurrency safety mechanisms, while hardly affecting execution speed. Rust also allows developers to build complex abstractions without incurring a performance penalty at runtime.

In contrast, Although the performance of Go programs is also good, the design focus is mainly on the speed of development (including compilation), rather than the degree of execution. Go programmers prefer clear and readable code, so the running speed is a bit slower.

The Go compiler also doesn't spend much time generating the most efficient machine code, it's more concerned with compiling large amounts of code quickly. **So in runtime benchmarks, it is often the Rust program that overwhelms the Go program. **

Rust's runtime performance is also very consistent and predictable because it doesn't use garbage collection. Go's garbage collector is very efficient and is optimized to keep pause times as short as possible (pause times get shorter with each release of Go). But anyway, garbage collection always introduces some unpredictability in the way the program behaves, and this can be serious or even completely unacceptable for certain applications (such as embedded systems).

Because Rust's goal is to give the programmer complete control over the underlying hardware, **Rust programs can be deeply optimized to approach the maximum theoretical performance of the machine. **This makes Rust the best choice for certain use cases where speed of execution trumps all else, such as game programming, operating system kernels, web browser components, and real-time control systems.

  • Simplicity

It doesn't matter how powerful a programming language is if it's too difficult to learn and keeps most people out. Go seems to be deliberately designed to distinguish itself from languages of increasing complexity such as C++: **It has very little syntax, very few keywords, and not even many functions. **

This means that the Go language is easy to learn, and you can write various programs with it after a little understanding.

Go is really easy to learn. I've heard this mentioned a lot before, but after using it I'm still amazed at how quickly it improves productivity. Thanks to the Go language, related documentation and tools, I wrote interesting and committable code in just two days.

—Rust Programmer's Early Impressions of Go

The key point here is "simplicity" three words. Of course, simple does not mean easy. But a small and simple language is definitely easier to learn than a large and complex language. There aren't many ways to achieve one effect, so high-quality Go code almost always looks the same. This has another benefit: we can quickly understand what a service with which we are not familiar is doing.

Rust VS Go, which language should developers choose in 2023?

**Go's core ontology is small, but the standard library is very powerful. **That is, in addition to the Go syntax, our learning curve must also take into account this part of the standard library.

On the other hand, transferring functions from the language to the standard library means that everyone only needs to focus on learning the libraries related to the current development needs. **Go is also designed with full consideration of the needs of large-scale software development, and can strongly support large code bases and development teams. **In this type of scenario, new developers must be able to get started quickly. To this end, the Go community has always prioritized simplicity, clarity, versatility, and directness of programs.

Using the GO language, it is often easier for junior developers to be productive, but it is harder for intermediate developers to introduce complex abstractions and thus cause problems. Because of this characteristic, Rust tends to be less attractive than Go in the world of enterprise software development.

— Loris Cro

  • Function

Rust supports more complexity than several other programming languages, so the corresponding implementation scope is also larger.

— Devathon

**Rust is specifically designed to include a variety of powerful and useful features that help programmers do more with less code. **For example, Rust's match function makes it possible to quickly write flexible and expressive logic:

Rust VS Go, which language should developers choose in 2023?

But also because Rust has a lot of design considerations, it is more difficult to learn, especially in the initial stage. But that's okay, C++ or Java has a lot to learn after all, and it doesn't even offer Rust's advanced features like memory safety. So it is really unreasonable to criticize Rust's too complicated sound: it is designed to emphasize expression and rich functions, we can't expect it to be so simple and pure while taking advantage of the benefits. So of course Rust has its own learning curve. But as long as this difficulty is overcome, there will be a smooth road ahead.

If you're ready to learn more complex syntax and semantics (and a higher bar for code readability) in exchange for the highest level of performance, Rust can even rival C++ and D. — Dave Cheney

**Although Rust and Go borrow some features from each other (such as generics), it is fair to say that Rust's features are still superior, and Go's features are relatively lacking. **

  • Concurrency

Most languages provide some form of support for concurrent programming (i.e. performing multiple operations at the same time), but Go was designed for this from the ground up. **Go does not use operating system threads, but provides a lightweight alternative: goroutines. **Each goroutine is an independently executing Go function that the Go scheduler maps to one of the operating system threads under control. That is, the scheduler can manage a large number of concurrent goroutines very efficiently, while only using a limited number of operating system threads.

Therefore, we can run millions of concurrent goroutines in a single program without worrying about causing serious performance problems. Because of this, **Go is a complete solution for large-scale concurrent application scenarios such as web servers and microservices. **

Go also provides channels for goroutines, which is a fast, safe, and efficient way to communicate and share data. Go's concurrency design level is indeed very high, and the usage experience is quite relaxed and pleasant.

In general, the design of concurrent programs is very difficult, and building reliable and correct concurrent programs in any language is by no means easy. However, since this requirement was considered at the beginning of the project, the concurrent programming mechanism in Go has been made as simple as possible and well integrated.

Go makes it easier to build a carefully deconstructed application that can be deployed as a set of microservices and take full advantage of concurrency. It's not impossible in Rust, it's just harder to implement. In a sense, Rust is more suitable for programmers who must not allow security holes caused by memory problems; but correspondingly, when they perform some tasks that are relatively simple for other languages (including GO), they prefer Have to pay more effort. —Sonya Koptyev

In contrast, the concurrency mechanism in Rust has just landed and has not yet been stabilized, so everyone is welcome to continue to pay attention to this active development direction. This is also beneficial. For example, Rust's rayon library provides a very elegant and lightweight method that can convert sequential calculations into parallel calculations.

It would be really nice to have a lightweight syntax for spawning goroutines and using channels. This is a direct manifestation of the power of grammar, and various small details also make Go's concurrent programming experience much better than other languages.

—Rust Programmer's Early Impressions of Go

While it may not be easy to implement concurrent programs in Rust, it's still perfectly doable, and** these programs also benefit from Rust's carefully designed memory safety guarantees. **Take the Mutex class of the standard library as an example: in Go, we may forget to acquire the mutex before accessing something; but in Rust, there is no need to worry about it at all.

Go focuses on concurrency as one of the core concepts. This is not to say that we cannot achieve concurrency effects similar to Go in Rust, but the difficulty of implementation is somewhat of a test for programmers. Go focuses on concurrency as one of its core concepts. This is not to say that we cannot achieve concurrency effects similar to Go in Rust, but the difficulty of implementation is somewhat of a test for programmers.

——Dave Cheney

  • safety

As mentioned earlier, both Go and Rust have their own ways to prevent various common programming mistakes, especially problems related to memory management. But **Rust goes further, it can be said that it spares no effort to ensure that everyone does not make unexpected security mistakes. **

Rust's compiler is so strict that it checks every variable we use, every memory address we refer to. It avoids potential data race conditions and also notifies you of undefined behavior. In the world of Rust, concurrency and memory safety issues are almost impossible to arise.

— Why choose Rust?

That said, the programming experience in Rust is different than almost any other language, and can be quite challenging when first introduced. But in the eyes of many developers, this effort is clearly worth the money.

For me, the biggest advantage of Rust is that the compiler has become my good assistant, it will not miss any detected bugs (seriously, sometimes it feels like magic to me).

—Grzegorz Nosek

Many languages, including Go, also provide tools to help programmers avoid mistakes, but Rust takes this effect to a new level. Many incorrect programs don't even compile at all.

In Rust, various library facilities help programmers prevent user errors. Rust allows us to specify a piece of data and then guarantee that it does not belong to or be tampered with by anything else. I can't think of a language that has provided so many tools to prevent accidental misuse before, which feels wonderful. — Sam Rose

"Fighting the borrow checker" is a must for Rust newcomers, but for the most part, the checker isn't really the enemy. The problems it finds are indeed real bugs (or at least potential bugs) in the code. It may force us to fundamentally refactor our programs to avoid such problems - If you really put correctness and reliability as your top priority, then this strict requirement is obviously a good thing.

From another perspective, can a new language that does not change the programming method be called a new language? And when using other languages, Rust teaches us to think safely, which is equally important.

If people choose Rust, it is often because of the guaranteed design it provides: safety about null pointers/data races, predictable runtime behavior, and complete control over the hardware. If this doesn't make sense to you, there's really no need to use Rust. After all, there is a price behind these benefits: it is difficult to get started. You have to break bad habits and master new concepts. In the beginning, everyone will be tortured to death by the borrow checker.

— Matthew Endler

The actual difficulty of getting started with the Rust programming model may depend on what other languages you have used before. Python or Ruby programmers might find Rust too restrictive, but others might find the clarity and unambiguous constraints nice.

If you're a C or C++ programmer and have spent weeks looking for memory safety bugs in the language, you'll love Rust. So "fighting the borrow checker" becomes "is this still possible with a compiler? Cool!"

— Grzegorz Nosek

  • Scale up

Today's server programs contain tens of millions of lines of code, written by hundreds of programmers, and are updated almost every day. In terms of design and development, Go fully takes into account the need to improve work efficiency in such an environment. Design considerations for Go include strict dependency management, adaptability of the software architecture as the system grows, and robustness across component boundaries. — Rob Pike

When you're solving a problem alone or in a small team, whether you choose a simple language or a rich language is purely a matter of personal preference. However, with the expansion of software scale, complexity, and team expansion, the differences between the two languages began to really emerge.

For large applications and distributed systems, the speed of code execution is often less important than the speed of development: a language like Go that deliberately emphasizes lean design can short the adaptation time of new developers and allow them to participate more quickly To contribute to large codebases.

Using the GO language, it is often easier for junior developers to be productive, but it is harder for intermediate developers to introduce complex abstractions and thus cause problems. Because of this characteristic, Rust tends to be less attractive than Go in the world of enterprise software development.

— Loris Cro

Clarity and legibility are always more important than elegance when it comes to large-scale software development. **Go's limitations actually make it more adaptable to the needs of enterprises and large organizations than more complex and powerful languages such as Rust. **

Rust vs. Go: Differences

While both Rust and Go are popular and widely used modern languages, they're not really competitors because they're targeting arguably completely different use cases**.

The whole approach to programming in Go is completely different from Rust, and these features are particularly suitable for some people, but on the other hand can completely irritate others. Which makes sense, because if Rust and Go are both solving basically the same problems in basically similar ways, why do we need two separate languages?

So, can we start with the approaches taken by Rust and Go and interpret their respective essences? Let's try it out together.

  • garbage collection

"To garbage collect, or not to garbage collect" is always a question with no right answer. In general, garbage collection and automatic memory management can help us develop reliable and efficient programs quickly and easily. So for some developers, these are essential features.

Others argue that garbage collection, with its performance overhead and global pauses, can lead to unpredictable runtime behavior and introduce unacceptable latency. Of course there is truth to this statement.

Go and Rust are two very different languages. Although both can be simply described as a system language or a substitute for C, their goals and application scenarios, language design styles and function priorities are indeed very different. Garbage collection is a big core differentiator. Garbage collection in Go makes the language simpler, smaller, and easier to understand. Rust does not have garbage collection, which makes it extremely fast (this is especially suitable for developers who require not only high throughput, but also low latency), and also realizes a series of functions and programming patterns that Go cannot do at all ( At least without sacrificing performance).

— PingCAP

  • close to hardware

The history of computer programming can be said to be an increasingly complex abstract development process. It allows programmers to solve problems without paying too much attention to how the underlying hardware actually operates. This design makes programs easier to write and more portable. But for other programs, access to hardware and precise control over how the program executes is more important.

**Rust's goal is to allow programmers to "close to the hardware" and regain more control; while Go abstracts away the architectural details, allowing programmers to get closer to the problem. **

Both languages have different areas of application. Go is good at writing microservices and typical "DevOps" tasks, but it's not a systems programming language. Rust is stronger in tasks that emphasize concurrency, safety, and/or performance, and does have a steeper learning curve than Go.

— Matthew Endler

  • Performance first

In fact, for most programs, performance is less important than code readability. But if some projects really put performance first, there are many design trade-offs in **Rust that will help you push the execution speed of your code all the way to the limit. **

In contrast, Go cares more about code simplicity, and is even willing to sacrifice some runtime performance for it. But Go's build speed is unparalleled, which is often even more important for large-scale code projects.

Rust performs faster than Go. In benchmarks, Rust is indeed faster, in some cases by an order of magnitude. But before you pick Rust, be clear: Go isn't far behind in most benchmarks, and it still maintains a performance advantage over languages like Java, C#, Java, and Python.

If you need top-notch performance, you can choose any of these two languages, and the speed performance will never disappoint. In addition, if you are building a web service that handles high-intensity loads and requires flexible vertical/horizontal scaling, both languages can also meet your needs.

— Andrew Lader

  • Correctness

On the other hand, if you don't force the program to never go wrong, the trade-offs will be different. Most code is not designed for long-term use, but some programs do run in production for years. Faced with these realities, it may be worth investing a little extra time in developing and ensuring that the program works correctly and reliably without incurring a heavy maintenance burden in the future.

Both Go and Rust help you write correct programs, but in different ways: **Go provides an excellent built-in testing framework, while Rust focuses on eliminating runtime bugs through borrow checkers. **

My opinion is: for code that has to be released tomorrow, use Go; if it is code that must run stably in the next five years, then choose Rust.

— Grzegorz Nosek

While both Go and Rust are good enough for serious development projects, it's best to fully understand their various features and advantages. In short, it doesn't matter what other people think: **Only you can decide which programming language is more suitable for your team and project needs. **

If you want to speed up development, say you have many different services to write, or the development team itself is large, then Go language is definitely the right answer. Go pays special attention to design for concurrency, and is keen to spot unsafe memory access behavior (as does Rust), but doesn't force you to manage every detail individually.

Go is fast and powerful, but at its core it helps developers get out of the way and focus on simplicity and unity. On the other hand, if you need to squeeze every ounce of performance headroom, Rust is ideal.

—Andrew Lader

Conclusion I hope this article can help you understand the respective highlights of Rust and Go. If possible, you'd better experience these two languages a little bit, because they are very useful in any technical path, even for amateur programming enthusiasts.

But if you only spend your time studying one language seriously, please make sure of the respective expertise and inclinations of Go and Rust before making a choice.

Of course, knowledge of programming languages is only a small part of what makes a successful software engineer. In addition to programming, engineers have to be proficient in design, engineering, architecture, communication and collaboration. As long as everyone can do the following things well, no matter which programming language you choose, you will become an excellent software engineering master.

View Original
  • Reward
  • Comment
  • Share
Comment
No comments