Hexinverter ¬ New Project: Conway's game of life in every language

Project repository: https://github.com/chaomodus/gameoflife

Well, okay not EVERY language, but I find that it helps me get a feel for the language and its quirks to implement Game of Life (a simple cellular automaton) in it. I went ahead and checked in my old, old C implementation that prints ANSI control codes to manipulate the terminal and is really messy, and a new implementation in Javascript targeting the HTML5 canvas, so here follows some musings about Javascript.

A project like this, while not complicated, really underlines how you can use a language a lot and not really get a lot of things about it. The first little bit of weirdness is copying a deep array. This idiom is used:

var newworld = []
for (var i = 0; i < world.length; i++) {
newworld[i] = world[i].slice();
}

There is no way that I would've come up with this, and it seems really counter intuitive to use slice to create a clone of an array. Similarly, creating an array with values, and having to resort to Underscore.js ... why is this not built in?

As an aside, I realize while writing this that a much more efficient way of doing this would be to have an extra copy of the world all of the time, and not create new arrays for each generation (I will do it this way when I rewrite the code as a proper object).

The second thing that strikes me is that Canvas is seriously weird and hard to work with. After extensive searching and significant experimentation, I was unable to figure out how to make a 1:1 pixel drawing on the canvas. I get close (pixels are perhaps 6x6 scaled up rectangles with blurry edges), but it will not draw the imagedata at its native resolution (incidentally, it's weird that you can't just write pixels to the canvas without the fairly hokey imagedata thing, but I suppose I could see reasons for this). I'll leave it here for now, but I'll be revisiting with alternate ways of drawing the cells and more experimentation with the imagedata method.

All in all I'm fairly satisfied with this as a prototype implementation, but it's not at all pretty. Next project will clean up the code and package it better, as per the TODO items.

For the future, more implementations in more languages and with more environments and techniques. A fun little project that I'm already enjoying.