{"id":15928,"date":"2024-06-13T10:01:30","date_gmt":"2024-06-13T07:01:30","guid":{"rendered":"https:\/\/atostek.com\/?p=15928"},"modified":"2024-06-18T08:11:11","modified_gmt":"2024-06-18T05:11:11","slug":"the-advantages-of-programming-in-the-rust-language-for-reliable-and-secure-systems","status":"publish","type":"post","link":"https:\/\/atostek.com\/en\/the-advantages-of-programming-in-the-rust-language-for-reliable-and-secure-systems\/","title":{"rendered":"The advantages of programming in the Rust language for reliable and secure systems"},"content":{"rendered":"<p><b>The Rust programming language has emerged as a new solution, specifically designed to overcome the complexities associated with C and C++ programs. But what makes Rust such an effective solution, and why has it gained such popularity?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">For the past few decades, systems programming has been dominated by C and C++. Both languages have a long history and have maintained compatibility with it. Under modern standards, these languages require a significant amount of manual effort and demand vigilance from the programmer to avoid numerous subtle dangers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Rust programming language represents a fresh approach, designed to address the challenges found in C and C++. Rust has been gaining adoption due to its improved ergonomics, reliability, and safety.<\/span><\/p>\n<h2 id='performance-at-the-forefront'  id=\"boomdevs_1\">Performance at the forefront<\/h2>\n<p><span style=\"font-weight: 400;\">Like C\/C++, Rust is a compiled language known for its minimal overhead. Rust features an intelligent compiler and language constructs that eradicate the majority of memory handling bugs and common run-time issues.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Since most errors are checked at compile-time, the performance of Rust programs remains unaffected, ensuring they are on par with those written in C\/C++. Furthermore, Rust provides numerous high-level abstractions without overhead.<\/span><\/p>\n<h2 id='memory-safety'  id=\"boomdevs_2\">Memory safety<\/h2>\n<p><span style=\"font-weight: 400;\">Rust is a memory-safe language that prevents memory corruption and undefined behavior, significantly reducing the likelihood of software acting unpredictably. In contrast, it is very difficult to write practical C\/C++ programs without encountering undefined behavior. It facilitates easier analysis and debugging by catching issues in the coding phase, rather than allowing silent memory corruption that leads to unexpected behavior later on.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u201cUndefined behavior\u201d in a programming language means a situation where the execution outcome of a piece of code (\u201cbehavior\u201d)\u00a0 cannot be determined from the code and the language specification. An example of such a situation would be reading data from a memory location that is not initialized and making a decision based on such a data. The Rust language is specified so that undefined behavior cannot occur, except in specific places that are explicitly marked \u201cunsafe\u201d.<\/span><\/p>\n<h2 id='reducing-vulnerabilities'  id=\"boomdevs_3\">Reducing vulnerabilities<\/h2>\n<p><span style=\"font-weight: 400;\">Memory safety eliminates vulnerabilities that are often a frequent topic of concern due to critical security exploits discovered in widespread software. <\/span><a href=\"https:\/\/security.googleblog.com\/2024\/03\/secure-by-design-googles-perspective-on.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Google has reported<\/span><\/a><span style=\"font-weight: 400;\"> that two-thirds of their security vulnerabilities are due to memory corruption issues.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As a result, large companies are beginning to rewrite their critical software components in memory-safe languages, including Rust, to minimize attack vectors. The risk posed by memory-unsafe languages is considered so significant that <\/span><a href=\"https:\/\/www.whitehouse.gov\/oncd\/briefing-room\/2024\/02\/26\/memory-safety-statements-of-support\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">the US government has even recommended<\/span><\/a><span style=\"font-weight: 400;\"> against the use of memory-unsafe languages, such as C\/C++.<\/span><\/p>\n<h2 id='usability-and-reliability-a-programmer-s-perspective'  id=\"boomdevs_4\">Usability and reliability: A programmer&#8217;s perspective<\/h2>\n<p><span style=\"font-weight: 400;\">From a programmer&#8217;s perspective, memory safety might not be the primary selling point of Rust. The language is designed with usability in mind, laying a strong foundation for ergonomics, consistency, and software reliability. Rust projects are straightforward to set up, build, and maintain, with fewer technicalities to manage.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Moreover, Rust behaves in predictable ways, preventing many common issues by making them either impossible or clearly visible. This design philosophy is widely appreciated, as evidenced by Rust being voted the most loved language in<\/span><a href=\"https:\/\/github.blog\/2023-08-30-why-rust-is-the-most-admired-language-among-developers\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\"> Stack Overflow&#8217;s developer surveys<\/span><\/a><span style=\"font-weight: 400;\"> for the past several years.<\/span><\/p>\n<h2 id='boosting-productivity'  id=\"boomdevs_5\">Boosting productivity<\/h2>\n<p><span style=\"font-weight: 400;\">Ergonomics and reliability are not only more comfortable for developers but also enhance productivity. When less time is devoted to debugging and managing technical details, developers can focus more on the application logic of their projects. While productivity gains can be challenging to quantify systematically, their impact is undeniable.<\/span><\/p>\n<p><a href=\"https:\/\/www.theregister.com\/2024\/03\/31\/rust_google_c\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">A director of engineering at Google<\/span><\/a><span style=\"font-weight: 400;\"> has estimated that Rust is twice as productive as C\/C++. Furthermore, <a href=\"https:\/\/www.zdnet.com\/article\/programming-languages-its-time-to-stop-using-c-and-c-for-new-projects-says-microsoft-azure-cto\/\" target=\"_blank\" rel=\"noopener\">the CTO of Microsoft Azure<\/a><\/span><span style=\"font-weight: 400;\"> has argued that with Rust available, no new software projects should be initiated in C\/C++.<\/span><\/p>\n<h2 id='rust-in-robotics'  id=\"boomdevs_6\">Rust in robotics<\/h2>\n<p><span style=\"font-weight: 400;\">C\/C++ is commonly utilized in embedded and real-time systems, as low overhead and low latency are required. However, many safety-critical applications, such as in robotics and autonomous vehicles, require high guarantees for software correctness. Rust fits particularly well in this context, which is why we at Atostek prefer to utilize Rust for robotic applications.<\/span><\/p>\n<h2 id='when-might-rust-not-be-the-ideal-choice'  id=\"boomdevs_7\">When might Rust not be the ideal choice?<\/h2>\n<p><span style=\"font-weight: 400;\">Despite all the hype, Rust is still not the perfect solution for every programming challenge. If a large codebase is already written in C\/C++, integrating Rust modules may not be justified due to the complexity and effort required for language interfacing.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Moreover, in scenarios where efficiency is not a primary concern, languages with garbage collection and emphasis on immutable data may offer an easier development experience since they abstract away manual memory management. This is particularly relevant for quick and dirty prototyping, where Rust, with its strict coding requirements for precision and reliability, may not be the fastest language to work with. Examples of such languages are Haskell and Microsoft\u2019s F#.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Rust prioritizes safety and performance, which might be more challenging for Python programmers accustomed to a higher level of abstraction, while C++ programmers should find the transition to Rust&#8217;s complexities more natural, and even an easier tool to work with.<\/span><\/p>\n<h2 id='conclusion'  id=\"boomdevs_8\">Conclusion<\/h2>\n<p><span style=\"font-weight: 400;\">Rust is a language that promises to revolutionize the way we think about system-level programming. Its focus on performance, safety, and developer-friendly features make it an attractive option for new projects, especially in domains where reliability is paramount.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While the transition to Rust may pose challenges, particularly for teams deeply entrenched in C or C++, the potential gains in productivity, security, and software quality are compelling.<\/span><\/p>\n<p><strong>More about the topic<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">The Register: <\/span><a href=\"https:\/\/www.theregister.com\/2022\/12\/02\/android_google_rust\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Google says Android runs better when covered in Rust<\/span><\/a><\/li>\n<li><span style=\"font-weight: 400;\">The Register: <\/span><a href=\"https:\/\/www.theregister.com\/2023\/04\/27\/microsoft_windows_rust\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Microsoft is busy rewriting core Windows code in memory-safe Rust<\/span><\/a><\/li>\n<li><span style=\"font-weight: 400;\">National Security Agency: <\/span><a href=\"https:\/\/media.defense.gov\/2022\/Nov\/10\/2003112742\/-1\/-1\/0\/CSI_SOFTWARE_MEMORY_SAFETY.PDF\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Software Memory Safety<\/span><\/a><\/li>\n<\/ul>\n<p><strong>Read more about <a href=\"https:\/\/atostek.com\/en\/services\/software-engineering\/\">Atostek&#8217;s software engineering expertise<\/a>!<\/strong><\/p>\n<hr \/>\n<div style=\"padding: 1%; width: 780px; margin: 1%;\">\n<div style=\"float: left; width: 30%;\"><img decoding=\"async\" class=\"alignnone\" style=\"max-width: 80%;\" src=\"https:\/\/atostek.com\/wp-content\/uploads\/2024\/06\/atostek-alpi-tolvanen-0526_square.jpg\" alt=\"\" width=\"300\" height=\"300\" \/><\/div>\n<div style=\"float: right; width: 70%;\">\n<p style=\"font-size: 18px;\"><strong>Alpi Tolvanen<\/strong><br \/>\n<em>Software Designer<\/em><\/p>\n<p class=\"biography\">I started working at Atostek in 2022 and am currently engaged in robotics, utilizing Rust, C++, and Haskell. Before joining Atostek, I worked as a computational physics researcher at Tampere University. Additionally, I have been a Rust enthusiast in my free time since 2018.<\/p>\n<\/div>\n<div style=\"clear: both;\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Rust programming language has emerged as a new solution, specifically designed to overcome the complexities associated with C and C++ programs. But what makes Rust such an effective solution, and why has it gained such popularity? For the past few decades, systems programming has been dominated by C and C++. Both languages have a&hellip;<\/p>\n","protected":false},"author":24,"featured_media":15926,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[114],"tags":[620,253],"class_list":["post-15928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-programming-en","tag-rust-en","entry","has-media"],"_links":{"self":[{"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/posts\/15928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/comments?post=15928"}],"version-history":[{"count":8,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/posts\/15928\/revisions"}],"predecessor-version":[{"id":16061,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/posts\/15928\/revisions\/16061"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/media\/15926"}],"wp:attachment":[{"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/media?parent=15928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/categories?post=15928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atostek.com\/en\/wp-json\/wp\/v2\/tags?post=15928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}