Posts tagged "rust"

Rust Isn’t Going Anywhere and Here’s Why

Initially an alternative to C++, Rust was created by Graydon Hoare, a former Mozilla developer, and released in 2006. Ever since then, developers have slowly transitioned from preferring C++ to using Rust instead. Its popularity has continued to rise as well since its release.

Rust has more security measures compared to C++, protecting its data in ways its predecessor can’t. While Java uses garbage collection, which does slow down performance speed, Rust is still faster than Java. Against Python, Rust is inexpensive when it comes to fixing bugs in code. Rust is also more expressive and flexible compared to Go. Each of those popular programming languages has its own strengths but, when compared to Rust, there is at least one area that the latter excels in.

Due to its popularity and strengths that make it better in certain areas compared to other languages, Rust isn’t likely to go anywhere. Here are 5 reasons why that’s the case:

  1. It just keeps increasing.

While there are other languages like C++ that do have a bigger community of developers and libraries, Rust’s continues to grow. It already has over 50,000 development tools, frameworks, and libraries that have been created by Rust’s community of developers. Additionally, there’s a subreddit for the language that is highly active.

  1. It’s highly adaptable.

Commonly referred to a low-level programming language, Rust has good embedding capabilities and excellent for building 3D video games. Its compiler is one of its best features, with the safety of coding following close behind. This helps prevent the use of immutability as well.

  1. Proficient memory safety is its focus.

When it comes to memory management, Rust excels is protecting code and the data it collects. One of its best functions is its ability to let developers manage memory on top of the values it contains. In fact, keeping memory safe is a primary focus of Rust, as explained by its creator. A strict compiler and notifying the developer of any issues is how Rust helps with that.

  1. High-performance speed and flexibility are its strengths.

Running quickly, even with performance-critical tasks, is something Rust also does well. This allows Rust to perform faster than Scala and, in some cases, Java. Being statistically typed and holding data without needing overheads aids its performance speed too. By predicting that variables are immutable, Rust is able to be optimized easier and is more flexible.

  1. It’s backed by major corporations.

Rust is still considered a fairly new programming language. Even many companies who haven’t started using Rust plan to use it at some point in the future. Major corporations like Microsoft admitted to switching several infrastructures within its system over to Rust, though it does plan to continue using C++. Other major corporations using Rust include Mozilla, Dropbox, and Sentry. Even one of the world’s largest businesses, Amazon, has incorporated the language within its system. As Rust becomes even more popular, particularly with such influential companies backing it, this language is sure to continue being a major player in the worldwide development community.

Overview of the Rust Programming Language

What is Rust?

In this part, there are a few insights here about Rust; if you’re not very familiar with it, or probably you want to refresh your memory. If not, feel free to go to the next section.

A brief history

Rust just celebrated five years of stable Rust. Thus, if you look back at the archives, you will realize that the project started much earlier than that – it takes a while for the software to evolve into something stable!

The first release label on the GitHub repository is over eight years old (release-0.1). And the first on this repository celebrates ten years today (I wasn’t indeed at university!). Before that, there was a Rust repository, which dates back to 2006.

It is also evident that two versions of Rust have been released within the five years: edition 2015 (Rust 1.0) and edition 2018 (Rust 1.31). Though the new edition was not a significant breaking change – one can use 2015 and 2018 packages in a Rust application – it shows a good velocity in the development of Rust.

Why Rust? Reliability, performance, productivity: choose three

Rust makes itself a practical programming language focusing on all of the reliability, performance, and productivity.

Performance means that Rust programs should run with no outflow in terms of memory usage or pure speed. Rust is collected as opposed to interpreted. An interpreted language like JavaScript or Python necessarily dodges a performance outflow, even with the best-in-class JIT customization. For illustration, dynamic typing prevents some compiler usage. Second, Rust uses manual memory operation, as opposed to a scrap collector. Even though scrap collectors can be structured with a low-speed overhead, it needs a lot more memory, like 5x more memory.

The downside of collected languages with manual memory operation is that, traditionally, C and C++ have been the primary source of security vulnerabilities because manual memory operation is complex. However, around 70% of severe vulnerabilities in software such as Chromium, Firefox, or Microsoft products are memory safety issues.

It is where Rust comes into existence; with a more potent model of memory power and borrowing ignited into the type system, Rust enables you to write dependable programs even with manual memory operation. It is the essential novelty of Rust, but as regards this series of posts, Rust has more benefits than that.

On the other side, there is a slight developer outflow in understanding how the power and borrowing rule works, but Rust has improved on the aspect. Thus, if you want to know about the performance, there is always some developer overhead: either you use a completely managed language such as JavaScript, but you will face challenges when your operation gets slow, or you either use something more efficient like Go or Java, and you can still end up fighting the scrap collector if RAM constrains you, or you use C/C++ which will be effective but will create a disadvantage later when security vulnerabilities are noticed in your software. You can also spend some time learning Rust, but after, you have to worry about neither reliability nor performance.

The next pillar of Rust is productivity. It comes by giving access to both low-position primitives – as we’ve seen with efficient memory operation and high-position abstractions – made possible with a robust type system. This ability to span the entire abstraction spectrum enables software development in Rust productive. If you write code and software performance as one, being more effective in writing reliable code increases the software performance.

In this talk, Bryan Cantrill discusses that a program written in Rust without applying all possible optimizations was 35% faster than an original well-optimized C program. The reason was that Rust enforced sorted maps as a B-tree under a good abstraction. While B-tree maps are very efficient, it is much harder to write a generic B-tree library in C than in Rust because of the type system, so C programs usually end up with few optimized structures like red-black trees. Another illustration is the Hash Map structure of Rust, which now implements a harborage of Google’s Swiss Tables, and is thus more efficient than stud::unordered map in C++. Relatively insightful! A good illustration is the following which compares the productivity of C and Rust to two languages that should not be compromised on performance.

Rust – A Cross-Site Programming Language

According to the 2020 Stack Overflow inventor Survey, Rust is used by roughly 5% of clients and is the most preferred programming language, with 86% of Rust clients (among the users) willing to continue programming in Rust. There can be a bit of been bias here because Rust is a new language with a small inventor base, so the developers who use it are very likely to be curious – programming in Rust in their leisure time instead of a professional context. They could also work on reasonably new code – without the whole technical debt accumulated by older code that could induce further frustration in general.

But an intriguing insight is that Rust has held this “most preferred” language title for numerous years in Stack Overflow’s survey. And the satisfaction has moved from 83% to 86% in a year, while the inventor base grew from 3% to 5% of respondents. So it’s entirely possible that the improvements of Rust – in particular, the async/await feature – have brought in more satisfaction!

A truly cross-site language

The first aspect that enables Rust a programming language of choice for many use cases is that it works on numerous sites. The list of supported locations is just massive!

An essential part of keeping in mind is that Rust is a set of compiled languages; the compiler has to output a different binary for each site. The produced binaries even have to take the target CPU and the present libraries in the target OS. And we still find it unique that all of these sites are supported by a single compiler.

Given this long list of sites, we will categorize them in a (non-exhaustive!) list to summarize the use cases.

Desktop systems

The three popularly known systems for desktops (including laptops and servers) are in type 1 of supported sites. If you possess Windows, Linux, or OSX system released in the recent ten years, Rust is “sure to work” on it with exhaustive automated testing.

Aside from these fully supported systems, you will find more systems present in tier 2 and tier 3. For illustration, you can also write Rust programs for Windows XP (tier 3). Beyond these tiers, someone even managed to compute a Rust program for Windows 98.

Mobile applications

Although the Rust compiler does not ship on mobile, you can cross-compile Rust code in iOS and Android applications. The integration model is suitable for developing a native library written in Rust than in C/C++ and invoking it from the primary Android/iOS application.

· You can get started with this tutorial on Android and use the JNI crate to relate with Java from Rust code.

· There is a similar tutorial on iOS (note that it hasn’t been tested).

Web front-end with Web Assembly

Web Assembly, also known as Wasm, is an improving alternative to JavaScript, especially on the web front-end, as all the significant browsers assist it. Wasm explains a simple stack-based virtual machine, which browsers can run practically more efficiently than JavaScript due to bypassing all the scripting and text-based language that add advances to JavaScript. And most significantly, it enables one to build programs in languages like C++ or Rust and then compute them down to Wasm. With writing a Rust program targeting Wasm, your web front-end can also benefit from Rust’s rich library ecosystem. Although I don’t know the details yet, you can get an online book to start Web Assembly in Rust.

Embedded systems

On the contrary, the software spectrum is embedded systems. They constitute the lowest software platform related to hardware components, including operating system kernels, firmware, or boot loaders. There are various resources to get started with Rust in embedded systems.

· The Rust embedded working group coordinates several efforts.

· Real-Time For the vast (documentation), develop a simple “bare metal” app on an embedded system.

· Tock (source code), and embedded management system which enables to run of various mutually unreliable applications.

An intriguing part of Rust is that even if a rich standard library is present in the language, it is still not supported by all target sites, and specifically not on embedded sites. Nevertheless, one can compute Rust code in no stud mode, where only a few similar libraries are available. With no std, you can easily do some “basic” operations like performing arithmetic, manipulating memory, and controlling flow. You can also use particular CPU instructions inline assembly. The “basic” operations are usually enough to start programming on an embedded system! However, no std means that you do not get access to managements that need a supporting OS, like reading/writing files or even printing to the terminal output, for there is no supporting OS at the “bare metal” level of software.

However, the no std mode enables Rust to be used on embedded systems. It is compared to languages like Python or Java, for which you need to ship a virtual machine and runtime on a site before you can manage programs on it. For illustration, concepts like Java. Os file does not exist with no supporting OS to offer a file system.