January 11, 2020

Tic Tac Toe in pony

I've spent some time learning the pony programming language on the side and I thought it would be fun to write a small command line game using it. The result is published on github.

Tic Tac Toe is a nice example because it can be used to understand most primitives of the language and learn about the standard library along the way, side stepping most dependencies and build issues for now.

But first, why pony?

Personally I've been looking for a language much like erlang, which compiles to native code. Pony fits the bill nicely, even though it's still in early stages. However, the features available in pony already make for a really nice programming language.

Here are my personal highlights of the language:

  • it supports structural typing via interfaces:
// StateListener is used to inform clients of status updates
interface StateListener
    fun val updated(brd: Board box)

Any class fits above interface as long as it provides the methods requested in the interface definition, with the correct reference capabilities. I love this feature as it allows me to side step adapter and other constructs to use libraries in a manner which I need for the task at hand.
A very powerful and versatile feature.

  • union types, type aliases and n-tuples:
type Row is (A | B | C)        // a union type, Row is one of A, B or C

type Column is USize           // a type alias

type Address is (Row, Column)  // a tuple, grouping a Row and a Column and giving the concept a dedicated name

Union types are great for grouping different types under a common name, type aliases are great for giving more meaningful names to existing types and n-tuples are super useful for cases where you don't need a fully fledged class or structs.

The ponylang page packs a lot more features which make pony a great language; I recommend reading it for yourself to get a complete look of what pony can do.


However, there are also some things I'd consider shortcomings:

  • no ponyfmt. Introducing a standard formatting for a language opens for the door for many tools which consume or generate code, and ensure these tools integrate nicely into other code written by humans. Go has gofmt, Rust as rustfmt, and many other languages followed down this path too because of the usefullness of such tools. I really wish pony would get this too.

  • no incremental compilation. Ponyc is reasonable fast for small projects, but I don't think it'll be fast enough most real world applications. It always recompiles all dependencies, even if the change I made are local to my application code.

  • too many boolean operators, e.g. is and isnt. I wonder why the same cases can't be handled using == and !=? There's probably a case which could be made to make the language more compact.

  • more useful error messages. when you get a reference capability wrong the compiler does a good job highlighting the issue, but I'd find it more useful if it would also provide solutions to resolve issues with reference capabilities.


The ponylang ecosystem is still young, and many libraries you'd want are still missing or unstable (think protobuf, http), but I greatly enjoy writing small applications in pony.

If you haven't done so yet I recommend that you learn a little pony yourself.

© Raphael Randschau 2010 - 2020 | Impressum