On Life

http://en.wikipedia.org/wiki/Conway%27sGameof_Life>Conway’s Game of Life, that is. The Game of Life has increasingly become a topic of fascination in Ruby circles since Corey Haines began pushing it as the focial point of his Code Retreats.

In short, GoL it is a cellular automata with emergent properties. Which is to say that they can be nifty to watch once you set one in motion.

However, the point of a Code Retreat is to focus on taking small steps, via Test Driven Development, not so much to build a functioning GoL but more importantly to improve on basic skills.

Facilitating a Code Retreat at Ruby DCamp 2010 cinched my interest in hacking on cellular automata to improve my TDD skills. So, for the past few weeks, I’ve been eeking out time here and there to write a JavaScript GoL. While I’m reasonably pleased with the readability of the initial-outcome code, it’s CPU-intensive and unoptimized.

I went so far as to add support to my Game of Life for Lifewiki Plaintext input late last night in a mostly complete but slightly klugey way. And, unsurprisingly, having a good test suite made this addition trivial. However, for the sake of expediency, I used a Spidermonkey supported XML trick to simulate heredocuments in JavaScript.

Ultimately, I used the exercise as a test bed to further improve my Javascript, to wade deeper into Jasmine (a contemporary JavaScript testing framework), and to get my feet wet with Underscore.js (I don’t know how I’ve lived this long without it…) and Coffeescript.

Feel free to give my Game of Life a run. But run it in Firefox if you want it to work! And, be warned, it will hit your CPU hard. http://evan.tiggerpalace.com/Conway-s-Game-of-Life-in-Javascript/index.html

Posted by evan on Sunday, October 17, 2010

blog comments powered by Disqus