Live data from Hacker News

Pony: An actor-model, capabilities-secure, high-performance programming language

ponylang.io

141–150 of 284 posts

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#141
OK, so having poked around the documentation a bit, I do think the Pony documentation could use a lot more examples. But there's one reasonably concrete example here:

https://patterns.ponylang.io/data-sharing/isolated-field

Basically what I gather is:

1. Actors are like threads, but have data structures associated with them. Actors have functions like methods associated with them called "behaviors", which are called asyncronously. BUT, any given Actor will only ever have one thread of execution running at a time. So calling a "behavior" is like sending a message to that actor's thread, saying, "Please run this function when you get a chance"; "when you get a chance" being when nothing else is being run. So you know that within one Actor, all references to Actor-local data is thread-safe.

2. They have different types of references with different capabilities. Think "const *" in C, or mutable and immutable references in Rust, but on steroids. The extra complexity you do in managing the types of references means that they can get the safety guarantees of Rust without having to run a borrow checker.

So in the above example, they have a Collector actor with an internal buffer. Anyone can append a character tot he internal buffer by calling Collector.collect(...). Code execution is thread-safe because the runtime will guarantee that only one thread of Collector will run at a time. The data is of type 'iso' ("isolated"), which ensures that only one actor has a reference to it at any time.

Once the internal buffer gets up to 10, the Collector will transfer its buffer over to another Actor, called a Receiver, by calling Receiver.receive(...) with its own internal buffer, allocating a new one for subsequent .collect() calls.

But its internal buffer has a reference of type 'iso', bound to Collector. How can it transfer this data to Receiver?

The magic is in these two lines:

    let to_send = _data = recover Array[U8] end
This creates a new local variable, to_send. Then it atomically:

- makes a new Array[U8] of type iso

- assigns this new array t; Collector._data

- Assigns the old value of Collector._data to to_send

Now Collector._data has a new reference of type iso, and to_send has the old one.

Next we do this:

    _receiver.receive(consume to_send)
The "consume" ensures that to_send can't be referenced after the consume call. So the compiler can verify that Receiver.receive() will be the only one able to access the old value of _data that we passed it.

Sounds like an interesting approach; it would be nice to see more examples of realistic patterns like this; perhaps simple sequential programs broken down into multiple actors, or things like a simple webserver implementation, with some sort of shared state.

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#142

I wish these language websites would put an example of some code right there on the homepage so I can see what the language "feels" like. I finally found some code in the tutorials https://tutorial.ponylang.io/getting-started/hello-world

I think Nim has a good homepage, with some bullet points explaining what the language is all about coupled with several code examples. I'm not saying Nim is better, but I visited the page the other day and thought it was neat. https://nim-lang.org/

It still looks great with Javascript off, 3rd party frames disabled and no remote fonts, too, for us privacy nuts

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#143

Earlier quoted context omitted.

It is based on actors and "reference capabilities". These two blogs[1,2], could provide nice introduction. 1. https://blog.jtfmumm.com//2016/03/06/safely-sharing-data-pon... 2. https://bluishcoder.co.nz/2017/07/31/reference_capabilities_...

That's quite interesting, but it doesn't answer the question: Would the python program running on an interpreter written in pony deadlock or not?

It would livelock

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#144

Earlier quoted context omitted.

> in a world where there are many languages that do the same thing it really boils down to using the one with the syntax that you like the most Wat? If all languages were just syntax re-skinning, we really wouldn't need more than one compiler backend... Generally the semantic differences are much more important. Rust isn't interesting for its syntax, it's interesting for its ownership rules and borrow checker. Erlang…

You say that but I will never use Rust because of it's awful syntax, I'll stick with C/C++ and be happy and not miss out on anything. I don't know much about erlang so I have no comments on it.

> and not miss out on anything

I mean, you do you. No one is judging. The fact remains that Rust exists primarily because there are some features that C++ cannot reasonably provide

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#145
> Incorrectness is simply not allowed. It’s pointless to try to get stuff done if you can’t guarantee the result is correct.

This is more nuanced actually. And it could have implications and contradictions with "get stuff done". IfI can have a non-provable piece of code that serves me well 99% of the time I could save coding time at the expense of correctness and could fit the bill for my use case.

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#147

> Incorrectness is simply not allowed. It’s pointless to try to get stuff done if you can’t guarantee the result is correct. This is more nuanced actually. And it could have implications and contradictions with "get stuff done". IfI can have a non-provable piece of code that serves me well 99% of the time I could save coding time at the expense of correctness and could fit the bill for my use case.

Even academic mathematics and computer science work like that to a degree.

We get a lot of stuff done assuming P != NP, that no polynomial-time prime factorization algorithm for classical computers exists, that one-way functions exist, etc.

As long as assumptions are clearly stated and are routinely questioned it's fine to have them

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#148

Earlier quoted context omitted.

> Doesn't mean it's not true. True, it just means that it's idiotic, rather.

oof I'm pretty sure that's a fallacy, let me just consult the manual here...

Keep us updated.

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#149
post #143

Earlier quoted context omitted.

That's quite interesting, but it doesn't answer the question: Would the python program running on an interpreter written in pony deadlock or not?

It would livelock

I wouldn't call it a livelock, because I wouldn't expect the runtime to be doing any (useless) work on behalf of the program.

Still, trading deadlocks for livelocks is a net negative as they are harder to identify and diagnose.

Re: Pony: An actor-model, capabilities-secure, high-performance programming language

#150

Earlier quoted context omitted.

Within the context of your Pony program you'll never be deadlocked. The virtual machine you implement capable of universal compute, and not enforcing this constraint, can be internally deadlocked, but this doesn't prevent your other Pony code from progressing necessarily - the deadlock is an internal state for that virtual machine, formally guaranteed to be confined to it. I'd be hesitant to call this a "Pony runtime…

That's a bit like saying that pthreads is deadlock free because the Unix kernel can still schedule other programs. It is an useful guarantee, but it doesn't help fix my broken program.

Yes. If you want to encode soundness guarantees, you might want to look for a language with formal verification facilities instead, like Ada-SPARK.

I'm not sure if there are any languages that allow you to pass down / inherit language constraints specifically, maybe Lisp or similar can do that? But then often that unfortunately wouldn't be actually helpful, as these requirements usually come from the outside (like in your Python example, it comes from Python being specified such that you can encode deadlocking logic in your Python code).

For most everyone who aren't trying to implement the possibility of deadlocks in guestcode, this remains a useful property even without that.

Post reply on HN