Sunday, February 27, 2011

The difficulty of best-practices code patterns

OK, so now that I'm thinking more carefully about macros (in the context of publishing Javascript for Web apps), here's why they're important: because it's too damn hard to understand code when it's written to work right in all the fiddly-bit situations.

Case in point, this article about asynchronous code patterns in node.js. Go ahead, read it.

Now here's the thing. If you read that code, the first version, the synchronous version, is comprehensible. The final version, an asynchronous version that actually works and handles exceptions rationally - well, you can understand it given the presentation, but I defy you to run across that in the wild and tell me what it does, clearly, without the need for fifteen minutes of error-prone thought.

Macros help us get around that. If we think of that final pattern as the compiled version of whatever concept we're trying to express, then it's a lot more palatable. And that's why a universal macro language like Declarative is going to be really useful for a lot of different things.

No comments:

Post a Comment