by ggchappell · 10y ago · 0 comments
There are a few things I wonder about. From the first page of the tutorial (http://tutorial.ponylang.org/):
> It's exception safe. There are no runtime exceptions. All exceptions have defined semantics, and they are always handled.
This seems contradictory. Are there exceptions or not? EDIT. Apparently there are (http://tutorial.ponylang.org/expressions/exceptions/). But then I don't understand what the above means.
> It's deadlock free. This one is easy, because Pony has no locks at all!
This is nonsense. Deadlock happens when multiple processes/threads are waiting for each other. It is not caused by locks.
From another tutorial page (http://tutorial.ponylang.org/types/static-vs-dynamic/):
> There's no such thing as null, so your program will never try to dereference null.
But there is "None" (http://tutorial.ponylang.org/types/primitives/). How is "None" so different from this "null" that we want to avoid?
On the positive side:
As I said this looks interesting. The type system appears to have been well thought out. Intersections look like a sane way to provide functionality that other PLs either implement poorly (perhaps via "multiple inheritance"), or simply disallow.
And if the type system really does offer all the claimed guarantees, then it is a very good thing indeed.
The partial applications, the concurrency model, and the handling of immutability are also clearly features that someone has given a lot of thought to. I cannot judge the results at this point, but I like well-thought-out things. :-) And the notion of "apply", along with the shortcut syntax, seems like it provides a standard, easy to understand way to make lot of code pretty simple.
I hope to be able to look into this PL more closely in the near future.
> This seems contradictory. Are there exceptions or not? EDIT. Apparently there are (http://tutorial.ponylang.org/expressions/exceptions/). But then I don't understand what the above means.
I think the author is using a terminological Java-ism. In Java, a "runtime exception" (RuntimeException and subclasses) is an exception that doesn't have to be handled, and therefore may be thrown unhandled at runtime. Pony has exceptions, but no unhandled exceptions, i.e. no "runtime exceptions" in Java speak.
So the point is that a program will never crash due to an exception.
> This is nonsense. Deadlock happens when multiple processes/threads are waiting for each other. It is not caused by locks.
Actually deadlocks happen when 2+ resources are not locked in the same order by 2+ processes/threads... As far as I know, in Pony there's no way to send a blocking message to another actor, so there's no lock, so there's no deadlock.
Please correct me if I'm wrong
> A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.
That is from Modern Operating Systems, 4th ed. (2015), by A.S. Tanenbaum & H. Bos, page 439. (By "process" they really mean "process or thread".)
One way for thread A to wait on thread B is as you said: thread A can request a lock that thread B currently owns; then A waits for B. So requesting locks in opposite orders can result in deadlock. But of course if there are no locks, then no such waiting occurs, and so deadlock from this cause is impossible.
But there are other ways to wait. If var_a and var_b are shared variables, then code like the following might result in deadlock (The following code is in C; to simplify things, I'm assuming that data races and memory-access ordering are not issues.)
Thread A does:
var_a = 1;
while (var_b != 0) ;
var_a = 0;
And thread B does: var_b = 1;
while (var_a != 0) ;
var_b = 0;
If Pony is capable of executing code like the above, then deadlock is possible.Okay, supposing we have a definition of deadlock that agrees with your usage: sure. But then these "other problems" you mention will have exactly the same practical effect as deadlock, right? A program will hang, sometimes unpredictably, based on more or less random decisions made by some low-level scheduling algorithm.
And in that case, Pony's guarantee of no deadlock is (1) completely correct, and (2) completely meaningless, from the point of view of a programmer whose concern is that his code will behave as required.
Am I wrong? EDIT. Maybe: https://news.ycombinator.com/item?id=10903876
> How is `None` so different from this "null" that we want to avoid?
The difference is the defaults. Languages "with null" generally assume that any value can be null. Other languages, like Pony, do not allow any type to be null.Pony's "None" type is an example of a "unit type": a type with only one possible value. It's a totally different thing.
> Pony often uses the primitive None to indicate that something has "no value".
So that is not a special value that we can assign to any variable.
"None" would seem to be pretty pointless all by itself, but I guess we could do a union of any old type with "None", to get a result much like Haskell's "Maybe". And then the Pony type system would give us much the same guarantees as Haskell's would; so we get a nullable variable that still allows for typesafe operations -- e.g., dereferencing, if applicable. (I guess ....)
> Of course, it does have a value, so that you can check what it is, and the value is the single instance of None.From the page I linked above:
> var x: (String | None)
> Here we have an example of using a union to express an optional type, where x might be a String, but it also might be None.
That's pretty clearly a Maybe.
http://tutorial.ponylang.org/pattern-matching/match/#matchin...
I see how it can be used in new and different ways, and is definitely safer, but it's not like the idea of "that thing you want isn't here" goes away by introducing a None type.
Or to put it more simply: an exception will never crash a program.