11

计划自学一门语言,入门该选 Go 还是 Rust 呢?

 2 years ago
source link: https://www.zhihu.com/question/520535831
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

计划自学一门语言,入门该选 Go 还是 Rust 呢?

本人是个香港的高中生,学校在教C嘛,然后我就想在闲暇的时间慢慢自学一门语言。也不急着说要找兼职 工作什么的,就纯当兴趣使然了。可是网上的评价两边各有,…
174
76,114

79 个回答

看了其他几个答主的回答,他们大多是从公司的角度去考虑,考虑是否容易找工作以及发展前景。

我觉得这样的分析角度不对,你的描述里是一位高中生,那我就认为你是初学者,而且离进入社会工作还有较长的时间。你应该以培养兴趣为主去学习编程。

我本人是做go后端开发工作的,但我不建议你学go,因为go的应用比较局限,主要用于云原生、后端和区块链这几方面,这几个方面都需要比较多的基础和写代码之外的知识,其中后端是相对简单的也至少要学个数据库,云原生更是要相对全面的知识和自己的理解

也不建议学rust,这个真的不好学,对初学者理解有较大难度。我也学过rust,看过一个视频,我确信讲课的老师非常好,但看完以后还是云里雾里,让我写个什么简单功能我肯定写不出来,让我看代码可能能看懂个大概。我学过c、python、java、go,至少能流利使用java和go,有一定编程基础,我也学不会rust

我的建议是学的简单一点,能较容易的作出一个东西的。比如python,我大学时自学的python看了一本书,看完后机缘巧合,还帮别人写了一个程序赚了以前块钱,后来就基本没用过python,我实践过它能快速写出东西。第二个我推荐javascript,相比于后端,前端有更好的展示效果更容易让人产生兴趣。如果你想走技术路线,那学C/C++也很好,这个是各高级语言的基础,学好C/C++再去学别的都会容易很多

就在最近Go技术负责人Russ Cox连续发了14条推特炮轰AWS官方发布“Sustainability with Rust(Rust 的可持续性)”文章。先溯源事情前因后果,我们再来看学什么;

为Rust投资的AWS

2015年才上线的Rust,仅仅7年的发展时间,就成为了很多大厂的团宠。2021年的时候,Amazon、Facebook,微软以及谷歌等巨头公司大量招聘Rust语言的开发者。微软甚至表示Rust是C/C++最好的替代方案。

亚马逊对Rust的投资也是逐年在增加,并且说“在AWS,Rust正在迅速大规模的构建基础设施。”

2018年的时候AWS推出了第一款使用Rust编程语言开源的技术产品。最近也是发布了一套Rust,基于Linux的容器操作系统。

并且在发布新操作系统的时候为了证明Rust 的好不是空穴来风,就引用了一份对编程语言能源消耗和性能内存的研究报告,以此表示Rust在可持续性方面的优越。

就是因为文中对Rust的分析,导致Go语言技术负责人Russ Cox不满!

有什么不满

先来看看Russ Cox发布的一条不满内容:

翻译下,他表示本来不想多说什么,但是因为ZDNet也报道了一遍AWS发布的内容,所以他觉得需要简短的来说一下Go被误解的部分。

首先Russ Cox第一点不满是,他们引用的报告是2017年10月发布的,那时候Go 1.6 在2016年2月推出。所以表示那已经是过去式了。

其次就是报告显示C++比C多消耗34%的能量,56%的时间和14%的内存。Russ Cox表示:每一个C的程序都是一个有效的C++程序。所以C++根本没有报告说的那么糟糕!

光看上面的言论大家可能也没觉得对Go有什么影响,但是他接下来马上就说到,因为文章中提到了某一个聊天软件从Go语言切换到了Rust。Russ Cox反驳到,这就是对打中的误导,因为该软件中有一个服务是Go语言编写的,但是存在了一定的延迟问题,后来决定用Rust重写。所以才有了对比,但是从数据上来看,Rust看着好像优化了Go语言的延迟峰值,实际上表现总体是差不多的。

而 AWS 在对 Rust 服务器用新数据结构和更多 RAM 进行了大范围重写后,在旁边放了 Go 的原始图表,Russ Cox 对此表示:“这要么是对 Discord 原帖完全误解,要么就是公然作假。”

Russ Cox 翻看了原文,发现了该软件发布的文章对比数据是公平的,因为人家显示了Go服务器和同等条件的Rust服务器的比较。但是AWS的博文中,Rust服务器的性能并未单独列出来也没有和Go语言进行对比,所以他们是在歪曲事实。

是否有偏见?

Russ Cox 表达自己的观点之后,后续也说明了,他对Rust是没有任何偏见的。之所以站出来说这些,主要是因为对AWS本身对Go语言一系列的避而不谈以及误导言论不满。

实际上Russ Cox曾经就有写过Rust vs Go 的文章,该文章中是做出了一些对比。

但是最终的观点和结论是,Go和Rust 如何相互协同,它们在一起更好。

如果看到这里,还有人纠结Rust还是Go?还想对你们说:

  • 程序是什么?— 计算机组成原理。
  • 程序怎么被翻译?— 编译原理。
  • 程序怎么执行?— 操作系统的范畴
  • 怎么利用别人的成果来实现更好的数据组织?— 数据库相关
  • 怎么保证程序更容易维护和可读?— 这是设计模式和代码规范
百度 工程师

两门语言压根就不是一个领域用的。

golang主打云相关服务和容器。在web上跟java有一定竞争。属于比较接近业务的语言,相对高层。

有点,语法非常简单,简单到用大小写区分可见性,性能比java好一些,而且静态编译没有依赖问题

rust主要是做底层和基础设施的。语法对于没有很强cpp底子的人上手有点困难,cpp很强的人上手完全无压力。强调尽量在编译期发现问题,所以语法检查非常严格。因为这货偏底层,跟go根本不冲突。

rust想干掉cpp

golang想干java

我觉得在没有很强的基础条件下,可以先学go。

如果偏向做内核系统啥的就直接学rust。学术界系统软工很多顶会的实现都是用rust,学会这玩意一劳永逸,再去学习其他什么python,js,java,r,matlab,go砍瓜切菜so easy。问题在于rust真的很难,所以经常用来写相对小但是安全要求比较高的组件。

到时候就可以在同事同学面前装逼真大神,新的编程语言现学现用直接站撸。然后仰天长啸,深藏功与名

至于golang简陋,我不知道是哪位大神说的,google编译器团队水平不错了。国内还没有这样水平的编译器团队呢

所以先学哪个看你自己吧。反正我是golang,rust,java一起学的,不好的地方就是新语法记不住,有时候记混了,得查一下书或者文档。

中文编程专栏: zhuanlan.zhihu.com/codeInChinese

学以致用为好。

从这个角度看,Python更适合。

除了它是日常任务万金油之外,也可以很方便地进行新编程语言设计试验:

这两年看到不少此类语言项目如:你您/kaelang

rust语言与go语言

With Mozilla shrinking in total employees, what is going to happen with Rust?
随着Mozilla员工总数的减少,Rust将会发生什么?
Recently Mozilla announced and enacted a sizeable number of layoffs, citing the COVID-19 pandemic. Many within the Rust community at large began to worry about the future of the beloved Rust programming language.
Mozilla最近以COVID-19大流行为由宣布并实施了大量裁员计划。 整个Rust社区中的许多人开始担心心爱的Rust编程语言的未来。
There are over 5000 open issues on GitHub, the Rust-based Servo team is no more, and some of the internal Mozilla contributors to Rust have lost their jobs!
在GitHub上有超过5000个未解决的问题,基于Rust的Servo团队已不复存在,并且一些内部的Rust贡献者也失去了工作!
As with any major news, things that can affect a programmer's happiness are always going to cause a stir online. But guess what?
与任何重大新闻一样,可能影响程序员幸福的事情总是会在网上引起轰动。 但猜猜怎么了?
Rust会没事的! (Rust is going to be okay! )

And here’s why:
原因如下:微软喜欢Rust (Microsoft Loves Rust)
This one is far from a surprise, considering how vocal Microsoft is about their relationship with Rust. Even within this very article, you will hear about Krustlet and npm, both of which are overseen by Microsoft Engineering.
考虑到微软对他们与Rust的关系有多声音,这一点不足为奇。 即使在这篇文章中,您也将听到有关Krustlet和npm的信息,它们都是由Microsoft Engineering监督的。
Microsoft is getting tired of their once favored C++ and C code:
微软已经厌倦了他们曾经喜欢的C ++和C代码:
We can’t really do much more than we already have. It’s becoming harder and harder and more and more costly to address these issues over time.
我们实际上不能做的比以前更多。 随着时间的推移,解决这些问题变得越来越困难,越来越昂贵。
They have come to a consensus that Rust is the best alternative to C and C++ currently available.
他们已经达成共识, Rust是目前可用的C和C ++的最佳替代品
While they have concerns about its interoperability with C++, they have decided to get involved with Rust and the greater Rust community in order to continue the pursuit of Rusty solutions.
尽管他们担心它与C ++的互操作性,但他们决定加入Rust和更大的Rust社区,以继续追求Rusty解决方案。
亚马逊爱Rust (Amazon Loves Rust)
Many may not even realize it, but Amazon Web Services (AWS) is not only a strong advocate for Rust, they even sponsor it. As Rust relies on portions of AWS infrastructure to support release artifacts, libraries, source code, and to host doc.rs, it makes perfect sense.
许多人甚至可能没有意识到这一点,但是Amazon Web Services(AWS)不仅是Rust的坚定倡导者,甚至赞助了它 。 由于Rust依靠AWS基础架构的某些部分来支持发行工件,库,源代码以及托管doc.rs ,因此这是很合理的
Additionally, the AWS engineering team built an open-source virtualization technology called Firecracker which is built in Rust and available on GitHub under an Apache 2.0 license. Using Rust allows them to have speed, security, scale, and efficiency, which provide a wonderful environment for microVMs.
此外,AWS工程团队还构建了一种名为Firecracker的开源虚拟化技术,该技术内置于Rust中,并根据Apache 2.0许可在GitHub上提供。 使用Rust使它们具有速度,安全性,可扩展性和效率,这为microVM提供了绝佳的环境。
Finally, AWS also has an official Rust Lambda Runtime, allowing for Serverless Rust. Microservices are a great start for aspiring Rust developers.
最后,AWS还具有正式的Rust Lambda Runtime ,允许使用无服务器Rust。 对于有抱负的Rust开发人员来说,微服务是一个很好的开始。
Google喜欢Rust (Google Loves Rust)
Did you know that Google is building an operating system called Fuschia? The mission statement says it all:
您是否知道Google正在构建名为Fuschia的操作系统? 任务说明说了一切:
Security and privacy are woven deeply into the architecture of Fuchsia. The basic building blocks of Fuchsia, the kernel primitives, are exposed to applications as object-capabilities, which means that applications running on Fuchsia have no ambient authority: applications can interact only with the objects to which they have been granted access explicitly.
安全和隐私深深地融入了紫红色的体系结构中。 Fuchsia的基本构建模块(内核原语)作为对象功能公开给应用程序,这意味着在Fuchsia上运行的应用程序没有环境权限:应用程序只能与已明确授予其访问权限的对象进行交互。
Fuschia is built from the ground up using Rust, and is also an open platform that allows code from C++, Rust, Flutter, and Web technologies to run on it.
Fuschia是使用Rust从头开始构建的 ,也是一个开放平台,允许C ++,Rust,Flutter和Web技术上的代码在其上运行。
npm喜欢Rust (npm Loves Rust)
A little over a year ago, npm was facing a dilemma: Explosive growth that was gaining steam exponentially, and CPU intensive tasks that were bogging down servers and creating performance bottlenecks.
一年多以前,npm面临一个难题:爆炸性增长正成倍增长,而CPU密集型任务却使服务器瘫痪并造成性能瓶颈。
With an open mind, the npm engineering squad had a sort of internal hackathon where they rebuilt the authentication service from scratch in both Go and Rust, alongside a full rewrite in Node.js
坦率地讲,npm工程团队有一种内部黑客马拉松 ,他们在Go和Rust中从头开始重建了身份验证服务,并在Node.js中进行了完全重写。
It only took an hour to rewrite the authorization service using Node.js, which is no surprise. Unfortunately, the performance was similar to that of the legacy implementation — also no surprise, since Node.js is fast but the npm code was already pretty optimized.
使用Node.js重写授权服务只花了一个小时,这不足为奇。 不幸的是,其性能与传统实现的性能类似-也不足为奇,因为Node.js速度很快,但是npm代码已经进行了非常优化。
The Go rewrite took two days, but the team found the lack of a dependency management solution painful (I mean they are a system for Node Package Management after all).
转到重写了两天,但小组发现缺少一个依赖管理解决方案的痛苦(我的意思是他们毕竟为节点程序包管理系统)。
With Rust, the rewrite of the service took longer than both the JavaScript version and the Go version combined, totaling about a week to get up to speed in the language and implement the program.
使用Rust,该服务的重写花费的时间比JavaScript版本和Go版本的总和还要长,总共花费了大约一周的时间,以加快语言和实施程序的速度。
In the end, the team building the Rust version was enamored. They went looking for a programming language that was:
最后,建立Rust版本的团队迷上了。 他们去寻找一种编程语言,它是:

  • Memory Safe
    记忆安全
  • Easy to compile to a standalone and easily deployable binary
    易于编译为独立且易于部署的二进制文件
  • Fast enough to consistently outperform JavaScript
    足够快以持续胜过JavaScript

And found such a language in Rust.
并在Rust中发现了这种语言。
更多公司喜欢Rust (Many More Companies Love Rust)
From Dropbox, Cloudflare, Discord, and Fastly, we have only heard great things about Rust, namely, each companies’ usage and happiness with the language for their major critical services and infrastructure.
在Dropbox,Cloudflare,Discord和Fastly中,我们只听说过Rust的很棒的事情,即每个公司对主要关键服务和基础架构的语言的使用和满意度。
Rewriting a core service in a large company is hard, and even more so when using a relatively brand new language. Rust is only about 10 years old, whereas most languages are 20, 30, or 40+ years old!
在大型公司中,重写核心服务非常困难,在使用相对全新的语言时,更是如此。 Rust大约只有10年的历史,而大多数语言都已经有20、30或40多年的历史!
The fact that these engineering teams not only rebuilt something with Rust and also came out positive shows a lot of potential for more such projects.
这些工程团队不仅用Rust重建了一些东西, 而且表现出积极的事实,表明了更多此类项目的巨大潜力。
Furthermore, those using Kubernetes can also benefit from using Rust, as there is a kubelet that allows developers to write more concise and stable Kubernetes code at the system level, using Krustlet. This essentially allows an engineer to run WebAssembly workloads on Kubernetes in code written in Rust, rather than Go, the main supported language of Kubernetes workloads.
此外, 使用Kubernetes的用户也可以从使用Rust中受益 ,因为有一个kubelet允许开发人员使用Krustlet在系统级别编写更简洁,稳定的Kubernetes代码。 从本质上讲,这允许工程师使用Rust而不是Go(Kubernetes工作负载的主要支持语言)编写的代码在Kubernetes上运行WebAssembly工作负载。
开发人员喜欢Rust (Developers Love Rust)

As a matter of fact, Rust has been at the top of the developer survey from StackOverflow for four years in a row, citing:
事实上,Rust连续四年在StackOverflow的开发人员调查中名列前茅,理由是:
The short answer is that Rust solves pain points present in many other languages, providing a solid step forward with a limited number of downsides.
简短的答案是,Rust解决了许多其他语言中存在的痛点,这为有限的缺点方面迈出了坚实的一步。
And what about the 5000 GitHub issues for Rust that are currently open? Let’s break them down:
那么,目前有5000个关于Rust的GitHub问题呢? 让我们分解一下:
Of these 5K+ issues, a large chunk of them are actually enhancements - roughly 1800 issues. There are about 2000 bugs, but that would make up around half of all future development. And of these 2000 bugs, a hefty portion of them are duplicates or “feature not bugs” that some developer has opened to complain.
在这些5K +问题中,其中很大一部分实际上是增强功能-大约1800个问题。 大约有2000个bug,但这将构成未来所有开发的一半。 在这2000个错误中,其中很大一部分是重复的,或者是某些开发人员已经开始抱怨的“功能不是错误”。
So fret not.
不用担心。
爱锈 (You Love Rust)
How do I know this? Because you took the time to read this article — and that means a lot! This article is truthful and meant to reassure you that Rust is awesome and here to stay. Rust is a wonderful way to create memory-safe, high-performance applications and software, welcome to the future.
我怎么知道 因为您花了时间阅读这篇文章,所以意义非凡! 这篇文章是真实的,旨在向您保证Rust非常棒,并且可以继续存在。 Rust是创建内存安全的高性能应用程序和软件的绝妙方式,欢迎未来。
As of today, in August 2020, Rust is in the top 20 of the Tiobe index, with a strong chance to take over MATLAB, Objective-C, Groovy, and possibly even Ruby. Only time will tell.
截至今天,到2020年8月,Rust处于Tiobe索引的前20名中,有很大的机会接管MATLAB,Objective-C,Groovy甚至可能是Ruby。 只有时间证明一切。
Mozilla和Rust爱Rust (Mozilla and Rust Love Rust)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK