I enjoy reading code, and I decided that of a change, I want to read code that isn’t in .NET. The following is a review of Postman:
This is actually the first time that I looked at Coffescript code (beyond cursory glance at the tutorial a time or two). I got to say, it looks pretty neat. Take a look at the definition of a linked list:
Pretty, readable and to the point. I like that.
Then I got to a head scratching piece:
There are various things that refer to postie, but it wasn’t until I got to the bottom of the code that I saw:
So I guess that postie line is actually defining a null argument, so it can be captured by the class Postman class methods.
I’ll be the first to admit that I am not a JS / CoffeeScript guy, so sometimes I am a little slow to figure things out, this method gave me a pause:
It took a while to figure out what is going on there.
The first few lines basically say, skip the first argument and capture the rest, then call all the subscriptions with the new msg.
Note that this is preserving history. So we can do something with this.
There is also an async version of this, confusing called deliverSync.
Getting the notification is done via:
This is quite elegant, because it means that you don’t lose out on messages that have already been published.
I guess that you might need to worry about memory usage, but there seems to be some mechanism to sort that out too. So you can explicitly clean things out. Which works well enough, I guess, but I would probably do some sort of builtin limits for how many msgs it can hold at any one time, just to be on the safe side. I don’t actually know how you would debug a memory leak in such a system, but I am guessing it can’t be fun.
This code makes my head hurt a big, because of the ability to pass a date or a function. I would rather have an options argument here, rather than overloading the parameter. It might be that I am a bad JS / CoffeScript coder and try to impose standards of behavior from C#, though.
All in all, this seems to be a fairly nice system, there is a test suite that is quite readable, and it is a fun codebase to read.