Merge pull request #12395 from beamrolling/patch-1

翻译完成
This commit is contained in:
Xingyu.Wang 2019-02-14 23:40:32 +08:00 committed by GitHub
commit d5e4baab2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 96 additions and 95 deletions

View File

@ -1,95 +0,0 @@
beamrolling is translating.
Introduction to the Pony programming language
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming_keys.jpg?itok=O4qaYCHK)
At [Wallaroo Labs][1], where I'm the VP of engineering, we're are building a [high-performance, distributed stream processor][2] written in the [Pony][3] programming language. Most people haven't heard of Pony, but it has been an excellent choice for Wallaroo, and it might be an excellent choice for your next project, too.
> "A programming language is just another tool. It's not about syntax. It's not about expressiveness. It's not about paradigms or models. It's about managing hard problems." —Sylvan Clebsch, creator of Pony
I'm a contributor to the Pony project, but here I'll touch on why Pony is a good choice for applications like Wallaroo and share ways I've used Pony. If you are interested in a more in-depth look at why we use Pony to write Wallaroo, we have a [blog post][4] about that.
### What is Pony?
You can think of Pony as something like "Rust meets Erlang." Pony sports buzzworthy features. It is:
* Type-safe
* Memory-safe
* Exception-safe
* Data-race-free
* Deadlock-free
Additionally, it's compiled to efficient native code, and it's developed in the open and available under a two-clause BSD license.
That's a lot of features, but here I'll focus on the few that were key to my company adopting Pony.
### Why Pony?
Writing fast, safe, efficient, highly concurrent programs is not easy with most of our existing tools. "Fast, efficient, and highly concurrent" is an achievable goal, but throw in "safe," and things get a lot harder. With Wallaroo, we wanted to accomplish all four, and Pony has made it easy to achieve.
#### Highly concurrent
Pony makes concurrency easy. Part of the way it does that is by providing an opinionated concurrency story. In Pony, all concurrency happens via the [actor model][5].
The actor model is most famous via the implementations in Erlang and Akka. The actor model has been around since the 1970s, and details vary widely from implementation to implementation. What doesn't vary is that all computation is executed by actors that communicate via asynchronous messaging.
Think of the actor model this way: objects in object-oriented programming are state + synchronous methods and actors are state + asynchronous methods.
When an actor receives a message, it executes a corresponding method. That method might operate on a state that is accessible by only that actor. The actor model allows us to use a mutable state in a concurrency-safe manner. Every actor is single-threaded. Two methods within an actor are never run concurrently. This means that, within a given actor, data updates cannot cause data races or other problems commonly associated with threads and mutable states.
#### Fast and efficient
Pony actors are scheduled with an efficient work-stealing scheduler. There's a single Pony scheduler per available CPU. The thread-per-core concurrency model is part of Pony's attempt to work in concert with the CPU to operate as efficiently as possible. The Pony runtime attempts to be as CPU-cache friendly as possible. The less your code thrashes the cache, the better it will run. Pony aims to help your code play nice with CPU caches.
The Pony runtime also features per-actor heaps so that, during garbage collection, there's no "stop the world" garbage collection step. This means your program is always doing at least some work. As a result, Pony programs end up with very consistent performance and predictable latencies.
#### Safe
The Pony type system introduces a novel concept: reference capabilities, which make data safety part of the type system. The type of every variable in Pony includes information about how the data can be shared between actors. The Pony compiler uses the information to verify, at compile time, that your code is data-race- and deadlock-free.
If this sounds a bit like Rust, it's because it is. Pony's reference capabilities and Rust's borrow checker both provide data safety; they just approach it in different ways and have different tradeoffs.
### Is Pony right for you?
Deciding whether to use a new programming language for a non-hobby project is hard. You must weigh the appropriateness of the tool against its immaturity compared to other solutions. So, what about Pony and you?
Pony might be the right solution if you have a hard concurrency problem to solve. Concurrent applications are Pony's raison d'être. If you can accomplish what you want in a single-threaded Python script, you probably don't need Pony. If you have a hard concurrency problem, you should consider Pony and its powerful data-race-free, concurrency-aware type system.
You'll get a compiler that will prevent you from introducing many concurrency-related bugs and a runtime that will give you excellent performance characteristics.
### Getting started with Pony
If you're ready to get started with Pony, your first visit should be the [Learn section][6] of the Pony website. There you will find directions for installing the Pony compiler and resources for learning the language.
If you like to contribute to the language you are using, we have some [beginner-friendly issues][7] waiting for you on GitHub.
Also, I can't wait to start talking with you on [our IRC channel][8] and the [Pony mailing list][9].
To learn more about Pony, attend Sean Allen's talk, [Pony: How I learned to stop worrying and embrace an unproven technology][10], at the [20th OSCON][11], July 16-19, 2018, in Portland, Ore.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/5/pony
作者:[Sean T Allen][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[译者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/seantallen
[1]:http://www.wallaroolabs.com/
[2]:https://github.com/wallaroolabs/wallaroo
[3]:https://www.ponylang.org/
[4]:https://blog.wallaroolabs.com/2017/10/why-we-used-pony-to-write-wallaroo/
[5]:https://en.wikipedia.org/wiki/Actor_model
[6]:https://www.ponylang.org/learn/
[7]:https://github.com/ponylang/ponyc/issues?q=is%3Aissue+is%3Aopen+label%3A%22complexity%3A+beginner+friendly%22
[8]:https://webchat.freenode.net/?channels=%23ponylang
[9]:https://pony.groups.io/g/user
[10]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/speaker/213590
[11]:https://conferences.oreilly.com/oscon/oscon-or

View File

@ -0,0 +1,96 @@
Pony 编程语言简介
======
Pony一种“Rust 遇上 Erlang”的语言让开发快捷安全高效以及高并发程序更简单。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming_keys.jpg?itok=O4qaYCHK)
在 [Wallaroo Labs][1],我是副总工程师,我们正在构建一个用 [Pony][3] 编程语言编写的 [高性能分布式流处理器][2]。大多数人没有听说过 Pony但它一直是 Wallaroo 的最佳选择,它也可能成为你的下一个项目的最佳选择。
> "一门编程语言只是另一种工具。与语法无关。与表达性无关。与范式或模型无关。仅与管理难题有关" —Sylvan ClebschPony 的创建者
我是 Pony 项目的贡献者,但在这里我要谈谈为什么 Pony 对于像 Wallaroo 这样的应用是个好选择,并分享我使用 Pony 的方式。如果你对我们为什么使用 Pony 来编写 Wallaroo 甚感兴趣,我们有一篇关于它的 [博文][4]。
### Pony 是什么?
你可以把 Pony 想象成某种“Rust 遇上 Erlang”的东西。Pony 有着最引人注目的特性,它们是:
* 类型安全
* 存储安全
* 异常安全
* 无数据竞争
* 无死锁
此外,它被编译为高效的本地代码,它是在开放的情况下开发的,在 2-clause BSD 许可下可用。
以上说的功能不少,但在这里我将重点关注那些对我们公司来说采用 Pony 至关重要的功能。
### 为什么使用 Pony
使用大多数我们现有的工具编写快速,安全,高效,高并发的程序并非易事。“快速,高效,高度并发”是可实现的目标,但加入“安全”之后,就困难了许多。通过 Wallaroo我们希望同时实现四个目标而 Pony 让实现它们更加简单。
#### 高并发
Pony 让并发变得简单。一部分是因为通过提供一个自用的并发主张。在 Pony 语言中,所有的并发都是通过 [Actor 模型][5] 进行的。
Actor 模型在 Erlang 和 Akka 中的实现最为著名。Actor 模型从 1970 年出现,细节因实施而异。不变的是,所有计算都由异步消息进行通信的 actor 来执行。
你可以用这种方式来看待 Actor 模型:面向对象中的对象是状态+同步方法,而 actor 是状态+异步方法。
当一个 actor 收到一个消息时,它执行相应的方法。该方法可以在只有该 actor 可访问的状态下运行。Actor 模型允许我们以并发安全的方式使用可变状态。每个 actor 都是单线程的。actor 中的两个方法不会并发运行。这意味着,在给定的 actor 中,数据更新不会引起数据竞争或通常与线程和可变状态相关的其他问题。
#### 快速高效
Pony actor 安排了一个高效的工作窃取调度程序。每个可用的 CPU 都有一个 Pony 调度程序。这种每个核心一个线程的并发模型是 Pony 尝试与 CPU 协同工作以尽可能高效运行的一部分。Pony 运行时尝试尽可能保持 CPU 缓存。代码越少缓存越高运行得越好。Pony 意在帮你的代码与 CPU 缓存友好相处。
Pony 运行时还会有每个 actor 的堆因此在垃圾收集期间没有“stop the world”的垃圾收集步骤。这意味着你的程序总是至少能做一点工作。因此 Pony 程序最终具有非常一致的性能和可预测的延迟。
#### 安全
Pony 型别系统引入了一个新概念参考能力使得数据安全成为型别系统的一部分。Pony 语言中每种变量的类型都包含了有关如何在 actor 之间分享数据的信息。Pony 编译器用这些信息来确认,在编译时,你的代码是数据竞争和无死锁的。
如果这听起来有点像 Rust那是因为本来就是这样的。Pony 的参考功能和 Rust 的借用检查器都提供数据安全性;它们只是以不同的方式来接近它,并有不同的权衡。
### Pony 适合你吗?
决定是否要在一个非业余爱好的项目上使用一门新的编程语言是困难的。与其他方法想比你必须权衡工具的适当性和不成熟度。那么Pony 和你搭不搭呢?
如果你有一个困难的并发问题需要解决,那么 Pony 可能是一个好选择。解决并发应用问题是 Pony 存在的理由。如果你能用一个单线程的 Python 脚本就完成所需操作,那你大概不需要它。如果你有一个困难的并发问题,你应该考虑 Pony 及其强大的无数据竞争,并发感知型别系统。
你将获得一个编译器,它将阻止你引入许多与并发相关的错误,并在运行时为你提供出色的性能特征。
### 开始使用 Pony
如果你准备好开始使用 Pony你需要先在 Pony 的网站上访问 [学习部分][6]。在这里你会找到安装 Pony 编译器的步骤和学习这门语言的资源。
如果你愿意为你正在使用的语言做出贡献,我们会在 GitHub 上为你提供一些 [初学者友好的问题][7]。
同时,我迫不及待地想在 [我们的 IRC 频道][8] 和 [Pony 邮件列表][9] 上与你交谈。
要了解更多有关 Pony 的消息,请参阅 Sean Allen 2018 年 7 月 16 日至 19 日在俄勒冈州波特兰举行的 [第 20 届 OSCON 会议][11] 上的演讲: [Pony我如何学会停止担心并拥抱未经证实的技术][10]。
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/5/pony
作者:[Sean T Allen][a]
选题:[lujun9972](https://github.com/lujun9972)
译者:[beamrolling](https://github.com/beamrolling)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/seantallen
[1]:http://www.wallaroolabs.com/
[2]:https://github.com/wallaroolabs/wallaroo
[3]:https://www.ponylang.org/
[4]:https://blog.wallaroolabs.com/2017/10/why-we-used-pony-to-write-wallaroo/
[5]:https://en.wikipedia.org/wiki/Actor_model
[6]:https://www.ponylang.org/learn/
[7]:https://github.com/ponylang/ponyc/issues?q=is%3Aissue+is%3Aopen+label%3A%22complexity%3A+beginner+friendly%22
[8]:https://webchat.freenode.net/?channels=%23ponylang
[9]:https://pony.groups.io/g/user
[10]:https://conferences.oreilly.com/oscon/oscon-or/public/schedule/speaker/213590
[11]:https://conferences.oreilly.com/oscon/oscon-or