rust 編程入門
Rust has been voted Stack Overflow’s most loved programming language for five years in a row. This article will tell you why Rust is awesome.
Rust已連續五年被評為Stack Overflow最受歡迎的編程語言。 本文將告訴您為什么Rust很棒。
Rust is a systems programming language that you can use to write applications with high performance. Rust is used by some of the top tech companies like Dropbox and Cloudflare to deliver speed and concurrency to their customers.
Rust是一種系統編程語言 ,可用于編寫高性能的應用程序。 一些頂級高科技公司(例如Dropbox和Cloudflare)使用Rust來為其客戶提供速度和并發性。
For the last five years in a row, Rust has been voted as the most loved programming language.
在過去的五年中,Rust被評選為最受歡迎的編程語言。
But chances are, you might not have worked with Rust. Or worse, you might not have heard of it before. So let's learn more about it.
但是有可能,您可能沒有使用Rust。 或更糟糕的是,您可能以前從未聽說過它。 因此,讓我們進一步了解它。
為什么生銹? (Why Rust?)
Let’s look at why a developer would choose Rust.
讓我們看看為什么開發人員會選擇Rust。
Typical programming languages like Python and C++ abstract a lot of details away from developers.
諸如Python和C ++之類的典型編程語言從開發人員那里提取了許多細節。
If you are a junior developer working on a simple web application, this might not an issue. You just want to find a solution to a problem.
如果您是從事簡單Web應用程序的初級開發人員,那么這可能不是問題。 您只想找到問題的解決方案。
For large scale applications that millions of users will use on a daily basis, the ‘problem-solving’ approach will not work. More users consume more system resources. And more resources mean bigger bills for your company.
對于每天將有數百萬用戶使用的大規模應用程序,“問題解決”方法將行不通。 更多的用戶消耗更多的系統資源。 更多的資源意味著您公司的賬單更大。
This is where Rust shines. Rust combines ease of programming with access to core system configurations. Rust is built with memory-safety, concurrency, and security from the ground up.
這是Rust發光的地方。 Rust將易于編程與對核心系統配置的訪問結合在一起。 Rust從一開始就具有內存安全性,并發性和安全性。
Rust is a “systems programming language that focuses on speed, memory safety, and parallelism”.
Rust是一種“專注于速度,內存安全和并行性的系統編程語言”。
Rust is also considered to be a great alternative for C++. Rust offers high performance in addition to helping you eliminate common bugs caused by languages like C++.
Rust也被認為是C ++的絕佳替代品。 除幫助您消除由C ++之類的語言引起的常見錯誤外,Rust還提供了高性能。
Now that you know what Rust can do for you, let's look at Rust in detail.
既然您知道Rust可以為您做什么,那么讓我們詳細了解Rust。
起源 (?Origins)
Rust is an open-source programming language. It was first introduced to the world in 2010 by Graydon Hoare, while he was working at Mozilla. Shortly after, Mozilla began sponsoring this project and is still a core contributor to Rust.
Rust是一種開源編程語言。 Graydon Hoare在Mozilla工作時于2010年首次將其引入世界。 此后不久,Mozilla開始贊助該項目,并且仍然是Rust的核心貢獻者。
Rust started gaining popularity over the years. Even Microsoft uses Rust to build secure and safety-critical software components.
多年來,Rust開始流行。 甚至Microsoft都使用Rust來構建安全且對安全性至關重要的軟件組件。
核心功能 (?Core Features)
Let's look at some core features that make Rust stand out from other programming languages.
讓我們看一些使Rust在其他編程語言中脫穎而出的核心功能。
性能 (Performance)
Rust was built to be high performance form the ground up. Rust offers fine-grained control of memory management and has a minimal standard library.
Rust被構建為具有高性能的基礎。 Rust提供了對內存管理的細粒度控制,并且具有最小的標準庫。
If you look at some of the metrics shared by Figma, they had incredible improvements in performance once they switched to Rust.
如果您看一下Figma共享的一些指標 ,當他們切換到Rust時,它們在性能上有了驚人的提高。
Rust’s low memory footprint also makes it an ideal choice for embedded systems programming. You can use Rust to write software for IoT devices like home automation hubs, smart security systems, and so on.
Rust的低內存占用空間也使其成為嵌入式系統編程的理想選擇。 您可以使用Rust來為IoT設備(例如家庭自動化集線器,智能安全系統等)編寫軟件。
安全 (Security)
One of the major reasons Microsoft decided to root for Rust is its security.
微軟決定支持Rust的主要原因之一是其安全性。
The majority of vulnerabilities in Microsoft software were due to poor memory management in C & C++. This lead to simple yet powerful exploits like the Buffer Overflow exploit that had crippled Windows for years.
Microsoft軟件中的大多數漏洞是由于C&C ++中的內存管理不良所致。 這導致了簡單而強大的漏洞利用 ,例如使Windows癱瘓多年的“ 緩沖區溢出”漏洞 。
So Microsoft decided to look for the best alternative to C++. And they found Rust.
因此,Microsoft決定尋找C ++的最佳替代品。 他們發現了Rust。
Using Rust eliminates an entire class of security vulnerabilities from software applications. This helps companies build applications with better performance and higher security.
使用Rust消除了軟件應用程序中的一整類安全漏洞。 這有助于公司構建具有更好性能和更高安全性的應用程序。
并發 (Concurrency)
Concurrency is when two or more tasks start, run, and complete in overlapping time. Database operations are a great example to explain concurrency.
并發是指兩個或多個任務在重疊時間內啟動,運行和完成。 數據庫操作是解釋并發性的一個很好的例子。
When thousands of users are using your application at the same time to perform different actions, your database handles them concurrently. Concurrency is a key concept when it comes to scaling applications.
當成千上萬的用戶同時使用您的應用程序執行不同的操作時,數據庫將同時處理它們。 當擴展應用程序時,并發是一個關鍵概念。
Concurrency and parallelism are also built into Rust. Rust solves most of the concurrency problems during compile time by using the concept of Ownerships. Learn how Rust handles concurrency here.
并發和并行性也內置在Rust中。 Rust使用所有權概念解決了編譯期間的大多數并發問題。 在此處了解Rust如何處理并發 。
使用Rust (Working With Rust)
Now that you understand the core features of Rust, let's write a few lines of code. You can find installation instructions here if you want to try out Rust on your computer.
現在您了解了Rust的核心功能,讓我們寫幾行代碼。 如果要在計算機上試用Rust,可以在這里找到安裝說明 。
Let's start with a simple “Hello World!” function.
讓我們從一個簡單的“ Hello World!”開始。 功能。
// Main function
fn main() {println!("Hello World!");
}
Yep. That's pretty much it. Let's try to add two numbers.
是的 就是這樣。 讓我們嘗試將兩個數字相加。
// Main function
fn main() {let a = 100;let b = 200;println!("Result is {}",a+b);
}
Again, pretty standard. Now let's look at an array operation.
再次,相當標準。 現在讓我們看一下數組操作。
// Main function
fn main(){let arr:[i32;4] = [1,2,3,4];println!("array size is {}",arr.len());
}
If you look at line 3, we use “:[i32;4]”. Here we tell Rust that we are declaring an array of length 4 with 32-bit integers.
如果您看一下第3行,我們使用“:[i32; 4]”。 在這里,我們告訴Rust,我們正在聲明一個長度為4的數組,其中包含32位整數。
Declaring data types in detail is a key factor in improving the performance of a program. You are helping the compiler save time by explicitly declaring what type of data you are about to assign to a variable.
詳細聲明數據類型是提高程序性能的關鍵因素。 您通過明確聲明將要分配給變量的數據類型來幫助編譯器節省時間。
Letting the compiler figure out the data type is one of the main reasons you run into performance issues while scaling your application.
讓編譯器弄清楚數據類型是在擴展應用程序時遇到性能問題的主要原因之一。
Also, Rust is a statically typed language, which means it must know the types of all variables at compile time.
同樣, Rust是一種靜態類型的語言 ,這意味著它必須在編譯時知道所有變量的類型。
Though Rust is syntactically similar to C and C++, don't let its simplicity fool you. Rust does come with a steep learning curve. But it is totally worth it once you get a good grasp of the basics.
盡管Rust在語法上類似于C和C ++,但不要讓其簡單性欺騙您。 Rust確實具有陡峭的學習曲線。 但是,一旦您掌握了基本知識,就完全值得。
誰使用Rust? (Who Uses Rust?)
Now that you have a good grasp of what Rust is, let's look at who uses Rust.
既然您已經了解了Rust是什么,那么讓我們看看誰使用Rust。
微軟 (Microsoft)
Once a fierce adversary of open source, Microsoft is now an avid contributor to a number of open-source projects. Their .net core project is one of the most popular open-source frameworks used by developers today.
曾經是開源的激烈對手,Microsoft現在是許多開源項目的熱心貢獻者。 他們的.net核心項目是當今開發人員使用的最受歡迎的開源框架之一。
Microsoft has chosen Rust for security and performance-critical applications. Rust is also used extensively in Azure, especially in its IoT Edge platform to run AI applications on IoT devices.
Microsoft已選擇Rust用于安全性和對性能至關重要的應用程序。 Rust在Azure中也被廣泛使用,尤其是在其IoT Edge平臺中,以在IoT設備上運行AI應用程序。
投寄箱 (Dropbox)
Dropbox uses Rust to improve its data center efficiency. Rust is now powering core services of Dropbox serving more than 500 million users.
Dropbox使用Rust來提高其數據中心效率。 Rust現在為Dropbox的核心服務提供支持,為超過5億用戶提供服務。
Dropbox recently wrote a detailed article on how they re-wrote their core engine.
Dropbox 最近寫了一篇有關如何重新編寫其核心引擎的詳細文章 。
In Dropbox’s own words,
用Dropbox自己的話說,
Rust has been a force multiplier for our team, and betting on Rust was one of the best decisions we made.
Rust一直是我們團隊的力量倍增器,對Rust的押注是我們做出的最佳決定之一。
Rust was also a contributing factor that helped Dropbox move its infrastructure from AWS to its own data centers.
Rust也是幫助Dropbox將其基礎架構從AWS遷移到其自己的數據中心的一個促成因素。
菲格瑪 (Figma)
Figma is a cloud-based designing and prototyping tool that you can use in your browser. It is an excellent tool for designing, prototyping, and exporting your designs into code. Learn more about Figma here.
Figma是一種基于云的設計和原型制作工具,可以在瀏覽器中使用。 它是用于設計,制作原型并將設計導出到代碼中的出色工具。 在此處了解有關Figma的更多信息 。
Concurrency is crucial for a collaborative tool where many users will be working on a single design at a time. Figma used Rust to write a high-performance server that helped them scale their product and achieve the performance they were looking for.
并發對于一個協作工具至關重要,在協作工具中,許多用戶將同時處理一個設計。 Figma使用Rust編寫了一個高性能服務器,可以幫助他們擴展產品并實現他們想要的性能。
Here is the article Figma wrote about their experience with Rust.
這是Figma寫的關于他們在Rust方面的經驗的文章 。
TL; DR (TL;DR)
Rust is a systems programming language that has been voted as StackOverflow’s most loved programming languages, four years in a row.
Rust是一種系統編程語言,已連續四年被評為StackOverflow最受歡迎的編程語言 。
Rust gives you control over low-level details and provides remarkable improvements in speed and stability.
Rust使您可以控制低級細節,并在速度和穩定性方面取得了顯著改善。
It has helped companies like Dropbox, Figma, and Microsoft build better applications for their customers.
它已經幫助Dropbox,Figma和Microsoft等公司為其客戶構建更好的應用程序。
The language is being increasingly adopted by companies looking to scale their applications with higher performance and concurrency. Sounds interesting? Start learning Rust here.
希望通過更高性能和并發性擴展其應用程序的公司越來越多地采用該語言。 聽起來不錯? 從這里開始學習Rust 。
I regularly write about Machine Learning, Cyber Security, and DevOps. You can signup for my weekly newsletter here.
我定期撰寫有關機器學習,網絡安全和DevOps的文章。 您可以 在這里 注冊我的 每周新聞 。
翻譯自: https://www.freecodecamp.org/news/rust-getting-started-with-the-most-loved-programming-language/
rust 編程入門