Developers writing in Rust can be twice as productive as teams using C++ when it comes to rewriting code, according to one of Google's software executives.
Speaking at the UK Rust Nation conference Last week, Lars Bergstrom, engineering director for Google's Android team, said that Rust has firmly secured its place as the leading programming language both in terms of performance and security.
This last of these aspects, he noted, has been a recurring theme in recent months amid growing concerns about the use of non-memory-safe languages, including warnings from US lawmakers.
“Everyone is recognizing that software plays a crucial role not only in our critical infrastructure for our governments, but also for end users and the software that is delivered to them,” he said.
But comparing developer productivity between programming languages has often been difficult to measure. That is, Bergstrom noted, unless you're a company like Google, which has had hundreds of developers rewriting a lot of systems in recent years.
“Right now at Google, we've rewritten a lot of systems, whether we've ported them incrementally or rewritten them from C++, so we actually have some very concrete things we can say,” he said.
In 2021, Google said that the Android Open Source Project would support Rust in the development of the operating system as a key way to prevent memory safety bugs, which were the largest source of high-severity Android security vulnerabilities.
He said that when Google rewrites Go into Rust systems, it takes about the same size team and about the same amount of time to build it.
That means there's no loss of productivity when moving from Go to Rust, and Bergstrom said there were some benefits as well, such as lower memory usage in services that moved from Go and a “decreased defect rate” over time. in those who did it. has been rewritten in Rust.
Rewrites in Rust offer tangible benefits
Rewrites from C++ to Rust also generated significant benefits, Bergstrom said, especially in terms of the effort applied by developers.
“When comparing our C++ code rewrites in Rust… in all cases we have seen a more than double decrease in the amount of effort required to both build services in Rust and maintain and update services written in Rust. ”He revealed.
“That's something that's really important to us because C++ code is very expensive, these are big teams, there's a lot of work, there's a lot of risk, and so I'm really happy to be able to share some of that data. “
Bergstrom referenced a 2022 survey of Google developers who used Rust, which found that more than two-thirds were confident of contributing to the language's codebase within two months of learning it.
Still, Rust didn't win over everyone. About 15% said it took them three to four months, 8% said it took more than four months, and another 8% said they were still not productive.
Google is making a similar migration in the Java ecosystem by moving Java developers to Kotlin, he noted. For developers who traditionally work in Java, getting them comfortable and ready to contribute to Kotlin takes about eight weeks.
“So it takes us about the same time to retrain a C++ developer to use Rust as it does to retrain a Java developer to use Kotlin,” Bergstrom said.
Bergstrom also pointed to survey data that found that one in three said they became as productive using Rust as they were in other languages within two months of learning it. However, that is not the case for everyone.
A third also said it took them three to four months or more, while almost a third said they were still not as good at Rust as they had been at their previous languages.
More than half of respondents said that Rust code is easier to review than other languages. Similarly, 85% said they are more confident that their Rust code is correct compared to other languages.
“I'm fortunate in my 25-year career to have been a part of the beginning of many programming languages and have gone through the ecosystem and I think Rust has uniquely invested in tools, documentation and culture compared to all other languages. I’ve been with him,” he said.
No widespread rewrites expected in the short term
However, that doesn't mean there's any desire to go back and rewrite the millions of lines of C++ code within Android.
The vast majority of security flaws are in new code, he said, so reverting to old code that may have gone through rounds of fuzzers, sanitizers, and external security audits isn't worth the cost, but it's also not worth the risk. to introduce new ones. issues.
Rust has gained popularity in recent years, but it is by no means the most popular programming language. Stack Overflow's 2023 developer survey ranked it 12th on the list of most popular languages.
Likewise, Rust is only ranked 19th on RedMonk. Programming language classifications metrics.
However, Rust is considered a memory-safe language, unlike C++, so many organizations, including Google, have used it to rewrite old code.