Merge pull request #21526 from wxy/20210303-5-signs-you-might-be-a-Rust-programmer

TSL:sources/tech/20210303 5 signs you might be a Rust programmer.md
This commit is contained in:
Xingyu.Wang 2021-04-07 23:20:19 +08:00 committed by GitHub
commit f08704d5a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 71 deletions

View File

@ -1,71 +0,0 @@
[#]: subject: (5 signs you might be a Rust programmer)
[#]: via: (https://opensource.com/article/21/3/rust-programmer)
[#]: author: (Mike Bursell https://opensource.com/users/mikecamel)
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
5 signs you might be a Rust programmer
======
During my journey to learning Rust, I've noticed a few common behaviors
of fellow Rustaceans.
![name tag that says hello my name is open source][1]
I'm a fairly recent [convert to Rust][2], which I started to learn around the end of April 2020. But, like many converts, I'm an enthusiastic evangelist. I'm also not a very good Rustacean, truth be told, in that my coding style isn't great, and I don't write particularly idiomatic Rust. I suspect this is partly because I never really finished learning Rust before diving in and writing quite a lot of code (some of which is coming back to haunt me) and partly because I'm just not that good a programmer.
But I love Rust, and so should you. It's friendly—well, more friendly than C or C++; it's ready for low-level systems tasks—more so than Python, it's well-structured—more than Perl; and, best of all, it's completely open source from the design level up—much more than Java, for instance.
Despite my lack of expertise, I noticed a few things that I suspect are common to many Rust enthusiasts and programmers. If you say "yes" to the following five signs (the first of which was sparked by some exciting recent news), you, too, might be a Rust programmer.
### 1\. The word "foundation" excites you
For Rust programmers, the word "foundation" will no longer be associated first and foremost with Isaac Asimov but with the newly formed [Rust Foundation][3]. Microsoft, Huawei, Google, AWS, and Mozilla are providing the directors (and presumably most of the initial funding) for the Foundation, which will look after all aspects of the language, "heralding Rust's arrival as an enterprise production-ready technology," [according to interim executive director][4] Ashley Williams. (On a side note, it's great to see a woman heading up such a major industry initiative.)
The Foundation seems committed to safeguarding the philosophy of Rust and ensuring that everybody has the opportunity to get involved. Rust is, in many ways, a poster-child example of an open source project. Not that it's perfect (neither the language nor the community), but in that there seem to be sufficient enthusiasts who are dedicated to preserving the high-involvement, low-bar approach to community, which I think of as core to much of open source. I strongly welcome the move, which I think can only help promote Rust's adoption and maturity over the coming years and months.
### 2\. You get frustrated by newsfeed references to Rust (the game)
There's another computer-related thing out there that goes by the name "Rust," and it's a "multi-player only survival video game." It's newer than Rust the language (having been announced in 2013 and released in 2018), but I was once searching for Rust-related swag and made the mistake of searching for the game by that name. The interwebs being what they are, this meant that my news feed is now infected with this alternative Rust beast, and I now get random updates from their fandom and PR folks. This is low-key annoying, but I'm pretty sure I'm not alone in the Rust (language) community. I strongly suggest that if you _do_ want to find out more about this upstart in the computing world, you use a privacy-improving (I refuse to say "privacy-preserving") [open source browser][5] to do your research.
### 3\. The word "unsafe" makes you recoil in horror
Rust (the language, again) does a _really_ good job of helping you do the Right Thing™, certainly in terms of memory safety, which is a major concern within C and C++ (not because it's impossible but because it's really hard to get right consistently). Dave Herman wrote a post in 2016 on why safety is such a positive attribute of the Rust language: [_Safety is Rust's fireflower_][6]. Safety (memory, type safety) may not be glamourous, but it's something you become used to—and grateful for—as you write more Rust, particularly if you're involved in any systems programming, which is where Rust often excels.
Now, Rust doesn't _stop_ you from doing the Wrong Thing™, but it does make you make a conscious decision when you wish to go outside the bounds of safety by making you use the `unsafe` keyword. This is good not only for you, as it will (hopefully) make you think really, really carefully about what you're putting in any code block that uses it; it is also good for anyone reading your code. It's a trigger-word that makes any half-sane Rustacean shiver at least slightly, sit upright in their chair, and think, "hmm, what's going on here? I need to pay special attention." If you're lucky, the person reading your code may be able to think of ways of rewriting it such that it _does_ make use of Rust's safety features or at least reduces the amount of unsafe code that gets committed and released.
### 4\. You wonder why there's no emoji for `?;` or `{:?}` or `::<>`
Everybody loves (to hate) the turbofish (`::<>`) but there are other semantic constructs that you see regularly in Rust code. In particular, `{:?}` (for string formatting) and `?;` (`?` is a way of propagating errors up the calling stack, and `;` ends the line/block, so you often see them together). They're so common in Rust code that you just learn to parse them as you go, and they're also so useful that I sometimes wonder why they've not made it into normal conversation, at least as emojis. There are probably others, too. What would be your suggestions?
### 5\. Clippy is your friend (and not an animated paperclip)
Clippy, the Microsoft animated paperclip, was a "feature" that Office users learned very quickly to hate and has become the starting point for many [memes][7]. On the other hand, `cargo clippy` is one of those [amazing Cargo commands][8] that should become part of every Rust programmer's toolkit. Clippy is a language linter and helps improve your code to make it cleaner, tidier, more legible, more idiomatic, and generally less embarrassing when you share it with your colleagues or the rest of the world. Cargo has arguably rehabilitated the name "Clippy," and although it's not something I'd choose to name one of my kids, I don't feel a sense of unease whenever I come across the term on the web anymore.
* * *
_This article was originally published on [Alice, Eve, and Bob][9] and is reprinted with the author's permission._
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/3/rust-programmer
作者:[Mike Bursell][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/mikecamel
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/EDU_OSDC_IntroOS_520x292_FINAL.png?itok=woiZamgj (name tag that says hello my name is open source)
[2]: https://opensource.com/article/20/6/why-rust
[3]: https://foundation.rust-lang.org/
[4]: https://foundation.rust-lang.org/posts/2021-02-08-hello-world/
[5]: https://opensource.com/article/19/7/open-source-browsers
[6]: https://www.thefeedbackloop.xyz/safety-is-rusts-fireflower/
[7]: https://knowyourmeme.com/memes/clippy
[8]: https://opensource.com/article/20/11/commands-rusts-cargo
[9]: https://aliceevebob.com/2021/02/09/5-signs-that-you-may-be-a-rust-programmer/

View File

@ -0,0 +1,73 @@
[#]: subject: (5 signs you might be a Rust programmer)
[#]: via: (https://opensource.com/article/21/3/rust-programmer)
[#]: author: (Mike Bursell https://opensource.com/users/mikecamel)
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
你可能是 Rust 程序员的五个迹象
======
> 在我学习 Rust 的过程中,我注意到了 Rust 一族的一些常见行为。
![name tag that says hello my name is open source][1]
我是最近才 [皈依 Rust][2] 的,我大约在 2020 年 4 月底开始学习。但是,像许多皈依者一样,我还是一个热情的布道者。说实话,我也不是一个很好的 Rust 人,因为我的编码风格不是很好,我写的也不是特别符合 Rust 习惯。我猜想这一方面是因为我在写大量代码之前还没有没有真正学完 Rust其中一些代码又困扰了我另一方面是因为我并不是那么优秀的程序员。
但我喜欢 Rust你也应该喜欢。它很友好比 C 或 C++ 更友好;它为低级系统任务做好了准备,这比 Python 做的更好;而且结构良好,这要超过 Perl而且最重要的是它从设计层面开始它就是完全开源的这要比 Java 那些语言好得多。
尽管我缺乏专业知识,但我注意到了一些我认为是许多 Rust 爱好者和程序员的共同点。如果你对以下五个迹象说“是”(其中第一个迹象是由最近的一些令人兴奋的新闻引发的),那么你也可能是一个 Rust 程序员。
### 1、“基金会”一词会使你兴奋
对于 Rust 程序员来说,“基金会”一词将不再与<ruby>艾萨克·阿西莫夫<rt>Isaac Asimov</rt></ruby>关联在一起,而是与新成立的 [Rust 基金会][3] 关联。微软、华为、谷歌、AWS 和Mozilla 正在为该基金会提供了董事(大概也是大部分初始资金),该基金会将负责该语言的各个方面,“预示着 Rust 成为企业生产级技术的到来”,[根据临时执行董事][4] Ashley Williams 说。(顺便说一句,很高兴看到一位女士领导这样一项重大的行业计划。)
该基金会似乎致力于维护 Rust 的理念并确保每个人都有参与的机会。在许多方面Rust 都是开源项目的典型示例。并不是说它是完美的(无论是语言还是社区),而是因为似乎有足够的爱好者致力于维护高参与度、低门槛的社区方法,我认为这是许多开源项目的核心。我强烈欢迎此举,我认为此举只会帮助促进 Rust 在未来数年和数月内的采用和成熟。
### 2、你会因为新闻源中提到 Rust 游戏而感到沮丧
还有一款和电脑有关的东西也叫做“Rust”它是一款“只限多玩家的生存电子游戏”。它比 Rust 这个语言更新一些2013 年宣布2018 年发布),但我曾经在搜索 Rust 相关的内容时,犯了一个错误,这个名字搜索了游戏。互联网络就是这样的,这意味着我的新闻源现在被这个另类的 Rust 野兽感染了,我现在会从它的影迷和公关人员那里随机得到一些更新消息。这是个低调的烦恼,但我很确定在 Rust语言社区中并不是就我一个人这样。我强烈建议如果你确实想了解更多关于这个计算世界的后起之秀的信息你可以使用一个提高隐私我拒绝说 "保护隐私")的 [开源浏览器][5] 来进行研究。
### 3、“不安全”这个词会让你感到恐惧。
Rust语言再次强调在帮助你做**正确的事情**™方面做得非常好,当然,在内存安全方面,这是 C 和 C++ 内部的主要关注点不是因为不可能做到而是因为真的很难持续正确。Dave Herman 在 2016 年写了一篇文章,讲述了为什么安全是 Rust 语言的一个积极属性:《[Safety is Rust's fireflower][6]》。安全性(内存、类型安全)可能并不赏心悦目,但随着你写的 Rust 越多,你就会习惯并感激它,尤其是当你参与任何系统编程时,这也是 Rust 经常擅长的地方。
现在Rust 并不能阻止你做**错误的事情**™,但它确实通过让你使用 `unsafe` 关键字,让你在希望超出安全范围的时候做出一个明智的决定。这不仅对你有好处,因为它(希望)会让你非常、非常仔细地思考你在任何使用它的代码块中放入了什么;它对任何阅读你的代码的人也有好处,这是一个触发词,它能让任何不太清醒的 Rust 人至少微微打起精神,在椅子上坐直,然后想:“嗯,这里发生了什么?我需要特别注意。”如果幸运的话,读你代码的人也许能想到重写它的方法,使它利用到 Rust 的安全特性,或者至少减少了提交和发布的不安全代码的数量。
### 4、你想知道为什么没有 `?;`、`{:?}` 、`::<>` 这样的表情符号
人们喜欢(或讨厌)涡轮鱼(`::<>`),但在 Rust 代码中你经常还会看到其他的语义结构。特别是 `{:?}` (用于字符串格式化)和 `?;``?` 是向调用栈传播错误的一种方式,`;` 则是行/块的结束符,所以你经常会看到它们在一起)。它们在 Rust 代码中很常见,你只需边走边学,边走边解析,而且它们也很有用,我有时会想,为什么它们没有被纳入到正常对话中,至少作为表情符号。可能还有其他的。你有什么建议?
### 5、Clippy 是你的朋友(而不是一个动画回形针)
微软的动画回形针 Clippy 可能是 Office 用户很快就觉得讨厌的“功能”,并成为许多 [模因][7] 的起点。另一方面,`cargo clippy` 是那些 [很棒的 Cargo 命令][8] 之一,应该成为每个 Rust 程序员工具箱的一部分。Clippy 是一个语言整洁器,它可以帮助改进你的代码,使它更干净、更整洁、更易读、更惯用,让你与同事或其他人分享 Rust 代码时不会感到尴尬。Cargo 可以说是让 “Clippy” 这个名字恢复了声誉,虽然我不会选择给我的孩子起这个名字,但现在每当我在网络上遇到这个词的时候,我不会再有一种不安的感觉。
* * *
这篇文章最初发表在 [Alice, Eve, and Bob] [9]上,经作者许可转载。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/3/rust-programmer
作者:[Mike Bursell][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/mikecamel
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/EDU_OSDC_IntroOS_520x292_FINAL.png?itok=woiZamgj (name tag that says hello my name is open source)
[2]: https://opensource.com/article/20/6/why-rust
[3]: https://foundation.rust-lang.org/
[4]: https://foundation.rust-lang.org/posts/2021-02-08-hello-world/
[5]: https://opensource.com/article/19/7/open-source-browsers
[6]: https://www.thefeedbackloop.xyz/safety-is-rusts-fireflower/
[7]: https://knowyourmeme.com/memes/clippy
[8]: https://opensource.com/article/20/11/commands-rusts-cargo
[9]: https://aliceevebob.com/2021/02/09/5-signs-that-you-may-be-a-rust-programmer/