Read my book

I wrote books about Webpack and React. Check them out!

Thursday, January 20, 2011

Personal Projects - jsopo + speccer + jswiki

Whoa! It has been a while since the last post. :) In this post I'm going to show you what I have been up to since the last one. I've been busy wrapping up certain commercial project that just went to a closed beta. I'm going to cover that in a later post in good detail.

In this post I'm going to focus on a few small projects of mine, namely jsopo, speccer and jswiki. jsopo, a precompiler, focuses on providing operator overloading for JavaScript. speccer is a testing tool for Python providing simplified assertion syntax. jswiki aims to become a hub for JavaScript related resources given there's a lot of interesting material but it's all spread around the web.

jsopo - Operator overloading for JavaScript

This little project was inspired by this blog post by Mr. Belmonte. Basically it implements a simple way to provide operator overloading for JavaScript. In case you aren't familiar with theory of programming languages you probably went like "huh" at the last sentence. No worries, let's rewind a bit. :)

So what's operator overloading then? Consider a statement such as "a = b + c". Usually this sort of statement assigns the result of "b + c" to "a" unless you are dealing with some sort of reactive programming environment.

In this latter case the result of "a" would be defined dynamically based on the sum. This can be particularly useful in certain kind of user interface programming (layout constraints!) but for some reason the concept hasn't become that popular.

Let's just assume we are dealing with the aforementioned view. It is important to note that the result of "b + c" might not yield anything useful. What should happen if you are summing up two arbitrary objects? Especially in JavaScript this can be problematic.

In Python, for instance, it's possible to implement __add__ and __radd__ (reversed version) magic methods that define just this. Unfortunately there's no such mechanism in JavaScript. There is no simple way to overload operators.

Fortunately it's possible to hack around this limitation. How? Simply by implementing a precompiler that compiles your "b + c" kind of code to valid JavaScript like "add(b, c)". Now all we need to do is to implement "add" somewhere and define the exact behavior there.

The first version, tagged as v0.1.0, of my project handles just simple statements (ie. "a + b" but not "a + (b + c)"). It's also missing the JavaScript part (implementation of add etc.).

It might be interesting to extend the precompiler to support some other features as well. I would particularly like to allow trailing commas and perhaps some other, tiny syntactic tweaks. I would love to extend JS function argument syntax in particular. It's a bit crippled currently, at least compared to Python.

During the initial development of jsopo I developed Speccer, my testing tool, a bit further. I featured the idea earlier on this blog.

Speccer - Testing tool

Speccer aims to simplify testing by providing a sort of DSL (implicit asserts!) that meshes with Python. It generates some code using Python's native testing module, unittest, and then executes them. Simple as that.

It might be cool if it was possible to generate code for various target languages, JavaScript included. This would make it the "ultimate" testing tool, at least in my eyes. :)

I don't expect this tool to become popular. I will use it for my personal Python development just to drive its development, though. As mentioned earlier jsopo's tests have been written using it. I definitely prefer its simplified syntax as compared to vanilla unittest.

Massive List of JavaScript Game Engines and Wiki

A while ago Andrea Bianco asked me to recommend some JavaScript based game engine to him as he wanted to implement a game. As a result I compiled a little list of the games engines I happened to find.

The first version of the list must have contained less than ten engines. If you checked the link you probably saw it's quite a bit longer than that now. How is this possible?

I did a little social experiment. I posted the list on reddit and started to treat it as a community effort. As it happens people actually responded to my initiative! Now we have a nice list to refer to whenever we want to develop games. :)

As it happens the list started to escalate a bit and some further categories (Canvas etc.) appeared. To make it easier for people to modify the list I set up a small wiki at Github. It's still quite crude and missing a lot. It's a start at least. :)

I would like it to grow into a proper resource that works as sort of a hub for JavaScript people. There's a lot information around there. We are just missing a nice index. Perhaps this wiki will prove to be one.


I intend to keep on working on these projects as time/motivation permits. If you happen to have any ideas on how to develop them further, do let me know. I don't mind if someone wants to fork some of those tools either. The more we have tools around, the merrier. :)