What's Pony, anyway?
2017-11-09 21:47:38    482    0    0
lijim

Pony是一门非常有趣的编程语言:面向对象 (只有组合,没有继承) + Actor (异步行为) + 基于能力的数据安全 (类型安全+内存安全+异常安全+无数据竞争+无死锁)。

“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)

一门编程语言就是另一个工具。她无关乎语法,无关乎表达能力,甚至无关乎编程范式或模型。她就是要管理和解决困难的问题。

Pony是编译型强类型的具有Actor的语言。她的调度器相当简单而调度的代价很轻。具有"偷工作"(work stealing)的特性,能和现代CPU架构尽可能高效地处理工作。因为她的垃圾回收是在Actor里进行的,所以时延相当可预测,比较一致。

尽管是偏研究型的,已经用于开发金融计算技术和高性能并发大数据处理底层框架,如:

Wallaroo - Ultrafast and elastic data processing https://www.wallaroolabs.com

 

What's Pony, anyway?

Pony is an object-oriented, actor-model, capabilities-secure programming language. It's object-oriented because it has classes and objects, like Python, Java, C++, and many other languages. It's actor-model because it has actors (similar to Erlang or Akka). These behave like objects, but they can also execute code asynchronously. Actors make Pony awesome.

When we say Pony is capabilities-secure, we mean a few things:

  • It's type safe. Really type safe. There's a mathematical proof and everything.
  • It's memory safe. Ok, this comes with type safe, but it's still interesting. There are no dangling pointers, no buffer overruns, heck, the language doesn't even have the concept of null!
  • It's exception safe. There are no runtime exceptions. All exceptions have defined semantics, and they are always handled.
  • It's data-race free. Pony doesn't have locks or atomic operations or anything like that. Instead, the type system ensures at compile time that your concurrent program can never have data races. So you can write highly concurrent code and never get it wrong.
  • It's deadlock free. This one is easy, because Pony has no locks at all! So they definitely don't deadlock, because they don't exist.

We'll talk more about capabilities-security, including both object capabilities and reference capabilities later.

The Pony Philosophy: Get Stuff Done

In the spirit of Richard Gabriel, the Pony philosophy is neither "the-right-thing" nor "worse-is-better". It is "get-stuff-done".

  • Correctness. Incorrectness is simply not allowed. It's pointless to try to get stuff done if you can't guarantee the result is correct.

  • Performance. Runtime speed is more important than everything except correctness. If performance must be sacrificed for correctness, try to come up with a new way to do things. The faster the program can get stuff done, the better. This is more important than anything except a correct result.

  • Simplicity. Simplicity can be sacrificed for performance. It is more important for the interface to be simple than the implementation. The faster the programmer can get stuff done, the better. It's ok to make things a bit harder on the programmer to improve performance, but it's more important to make things easier on the programmer than it is to make things easier on the language/runtime.

  • Consistency. Consistency can be sacrificed for simplicity or performance. Don't let excessive consistency get in the way of getting stuff done.

  • Completeness. It's nice to cover as many things as possible, but completeness can be sacrificed for anything else. It's better to get some stuff done now than wait until everything can get done later.

The "get-stuff-done" approach has the same attitude towards correctness and simplicity as "the-right-thing", but the same attitude towards consistency and completeness as "worse-is-better". It also adds performance as a new principle, treating it as the second most important thing (after correctness).

Guiding Principles

Throughout the design and development of the language the following principles should be adhered to.

  • Use the get-stuff-done approach.

  • Simple grammar. Language must be trivial to parse for both humans and computers.

  • No loadable code. Everything is known to the compiler.

  • Fully type safe. There is no "trust me, I know what I'm doing" coercion.

  • Fully memory safe. There is no "this random number is really a pointer, honest."

  • No crashes. A program that compiles should never crash (although it may hang or do something unintended).

  • Sensible error messages. Where possible use simple error messages for specific error cases. It is fine to assume the programmer knows the definitions of words in our lexicon, but avoid compiler or other computer science jargon.

  • Inherent build system. No separate applications required to configure or build.

  • Aim to reduce common programming bugs through the use of restrictive syntax.

  • Provide a single, clean and clear way to do things rather than catering to every programmer's preferred prejudices.

  • Make upgrades clean. Do not try to merge new features with the ones they are replacing, if something is broken remove it and replace it in one go. Where possible provide rewrite utilities to upgrade source between language versions.

  • Reasonable build time. Keeping down build time is important, but less important than runtime performance and correctness.

  • Allowing the programmer to omit some things from the code (default arguments, type inference, etc) is fine, but fully specifying should always be allowed.

  • No ambiguity. The programmer should never have to guess what the compiler will do, or vice-versa.

  • Document required complexity. Not all language features have to be trivial to understand, but complex features must have full explanations in the docs to be allowed in the language.

  • Language features should be minimally intrusive when not used.

  • Fully defined semantics. The semantics of all language features must be available in the standard language docs. It is not acceptable to leave behaviour undefined or "implementation dependent".

  • Efficient hardware access must be available, but this does not have to pervade the whole language.

  • The standard library should be implemented in Pony.

  • Interoperability. Must be interoperable with other languages, but this may require a shim layer if non primitive types are used.

  • Avoid library pain. Use of 3rd party Pony libraries should be as easy as possible, with no surprises. This includes writing and distributing libraries and using multiple versions of a library in a single program.

 

Source: https://tutorial.ponylang.org/

References: https://blog.wallaroolabs.com/2017/10/why-we-used-pony-to-write-wallaroo/

 

 

上一篇: CentOS7上安装Python3

下一篇: React Component Patterns

482 人读过
立即登录, 发表评论.
没有帐号? 立即注册
0 条评论
文档导航