Sam Gentle.com

Prototyping

I've been spending more time working on prototypes recently, as in code that you write to figure something out or explore an idea, rather than having a particular end goal. It seems like it's very easy to get fixated on trying to achieve something, but there's also a lot that you can get out of not achieving anything and just sort of seeing where the code takes you. That tends to happen at the start of any new project anyway, but it feels even better without the vague sense that I should stop screwing around and get things started.

A recent prototype I made is promserver, a minimal Promise-based webserver. The goal is to make something with very few features that just does the minimal work necessary to bridge between some code and the web. Here's what a hello world server looks like:


promserver 8000, (req) -> "hello, world!"

And you can return an object if you want headers and things:


promserver 8000, (req) ->
  status: 418
  headers: "X-IS-A-TEAPOT": "SHORT AND STOUT"
  body: "I'm a little teapot!"

The fields are modeled after the fetch API, and anything in a Promise is automatically unwrapped so you can do fun things like this:


promserver 8000, (req) -> fetch "http://google.com"

I think it's pretty nifty for a couple hours messing around. I'm not sure it'll go anywhere, but I'm also not sure it needs to. Chip also came out of some similar experimentation earlier. I think this prototyping thing has been a big win so far; the consequences of experimenting like this seem disproportionately good.