Design rationale - mfichman/jogo GitHub Wiki

Reference counting

All objects in Jogo are reference counted. While this seems like a step backwards from true garbage collection, in many areas the deterministic behavior of reference counting is desirable. While the amortized performance of reference counting may be worse than some garbage collection techniques, the performance is predictable and "even." That is, there will be no long GC pauses with reference counting. This is important for interactive applications like video games.

Structural typing

Structural typing provides more flexibility than nominal typing (e.g., Java interfaces) and allows duck-typing-like behavior in a statically-typed language. Jogo's virtual dispatch is not as fast as C++ virtual dispatch, but the flexibility afforded by structural typing aligns with Jogo's goal for powerful, scripting-language-like semantics. Note: While not directly influenced by Google's Go until recently, Jogo's type system is pretty similar to Go's. Originally, the idea to use structural typing in Jogo was influenced by Haskell's type classes, which are similar to structural typing. Recently, I've been looking to Go for some "design leadership" in the area of structural typing, because there aren't many languages with this type system.

Closures

Considering that closures can be simply implemented in terms of objects, it is silly for any object-oriented programming language to fail to support them. This opinion is reflected in the recent addition of closures to C++.

Coroutines

Jogo avoids threads, and uses an asynchronous I/O model beneath a coroutine layer. Coroutines allow thread-like, straight-line code to be written, while still using non-blocking I/O. Languages like JavaScript have a powerful asynchronous model, but suffer from stack-ripping. Coroutines can transform an event-driven program into straight-line imperative code without the overhead associated with threads (context-switching, wasted stack space, etc). Note: The original influence for Jogo's coroutines is Lua. However, Go has also taken the idea of coroutines to heart; in the future, design ideas might come from that language as well.

Dynamic stack

Rather than allocate a large fixed stack, Jogo allocates a dynamic stack for each coroutine. The cost is a 3-instruction preamble at the start of each function (to check the stack pointer), but the advantage is the ability to run thousands of coroutines at once. This is important for video game programming, where each "unit" or "AI entity" can run inside a separate coroutine.