

A Readable Conway's Game of Life - gsabo
http://blog.gsabo.com/game-of-life.html

======
ihodes
Very cool, and nice code. Just to be pedantic (I mean it in the best way),
this isn't quite literate programming.

A very basic explanation would be: literate programming is the result of
writing a program in a sort of psuedo-code that explains the program in the
order of the programmer's thoughts, and then running it through a compiler of
sorts which "untangles" the literate program and outputs machine-readable
code.

The linked post is nicely formatted and well-documented "regular" code.

~~~
gsabo
Thanks for pointing that out! I had assumed that Literate Programming was
simply any programming with a focus on human readability. I've changed the
title of the post and credited you at the bottom.

------
agentultra
The simplest version (and by my yard-stick is the de-facto measure of
"readability") I've seen was at Pycon 2012
([http://azd325.github.com/Python/2012/03/23/pycon-2012-stop-w...](http://azd325.github.com/Python/2012/03/23/pycon-2012-stop-
writing-classes/) around 17:30). The main take away that is demonstrated is
that classes aren't necessary to write this program but it's the first thing
most programmers reach for when implementing it.

Another thing I find a lot these days are an abundance of comments that
explain what the code already explains. Some of the comments are good in this
example, but many of them explain what I would know if I just read the code.

However, I do like the use of color! A great demonstration. Good work. :)

~~~
gsabo
I took your comment to heart and removed most of the comments in the source. I
found the video inspiring (and infuriating) - just more proof that I'm a long
way from unlearning my OO design tendencies. To start, I made the Neighborhood
class a function instead. Thanks for sharing.

------
fsiefken
Reminds me of an even more reabable coffeescript example posted a year ago on
HN: <http://willbailey.name/conway/docs/conway.html>

------
losvedir
And, conversely, an unreadable Game of Life in one line of APL (with
explanation): <http://www.youtube.com/watch?v=a9xAKttWgP4>

~~~
robomartin
What do you mean? It's perfectly readable if you know APL.

------
wollw
I've been working on a sculpture project[1] based on cellular automaton for
the past two semesters. It's not exactly conway's game of life as I'm mostly
focused on polygonal cells. Hardware wise it's mostly just LEDs with shift
registers and an ATtiny85 but the code[2] might be interesting to some, in
particular dealing with figuring out what cells are and aren't neighbors when
you have an ambiguous layout. I've also put together an Android simulator[3] I
use for exploring ideas that defines designs using JSON but I've put a lot
less work into it.

[1] <http://wollw.github.com/automaton-avr/>

[2] <https://github.com/Wollw/Cellular-Polymaton>

[3] <https://github.com/Wollw/Polymaton>

------
jastanton_
Oh what the heck, because we're all sharing our Conways Attempts here is mine:
<https://github.com/JAStanton/conways-game-of-life>

And the live version: <http://www.jastanton.com/experiments/conways-game-of-
life/>

Mine acts more like a game, you can start and stop with 's' and enter draw
mode with 'd' and draw on the cells.

~~~
gsabo
The logical simplicity of the rules makes it impossible to resist
implementation, it seems :) I love being able to draw on your version - I
missed out on implementing drag events.

I notice that you separate your "views" (this.cells) from your "models"
(this.grid). This seems like a good idea from an MVC perspective, but I would
worry that I'm forgetting to keep them in-sync in all cases.

------
ertdfgcb
somewhat unrelated: The most beautiful implementation of life that I have ever
seen is this 7 line Clojure one. It really turned me on to the value of using
data structures that match the problem well.

<http://clj-me.cgrand.net/2011/08/19/conways-game-of-life/>

------
huhtenberg
Another idea for colors is to use progressively more transparent pixels for
older generations. Add a bit of a hue shift and it renders some really
beautiful decay visualizations.

------
dethstarr
Good job. I enjoyed looking at the output from an artistic point of view.

------
wsbail29
nice implementation! The color adds a lot of visual interest. Here's my
monochrome implementation.

<http://wsb.im/conway/index.html>

~~~
jlarocco
Here's a non-literate, Javascript version I made using WebGL for the graphics:
<https://github.com/jl2/WebGL-Stuff/tree/master/life_game>

And the "live" code: <http://jlarocco.com/life_js/index.html>

Seems Conway's Game of Life has been popular lately.

~~~
gsabo
Bravo on making it work with WebGL! It's super smooth.

I see we both went with variable names like 'up' and 'left' for the subscripts
in the "neighbor count" code. I'm always looking for ways to sidestep
numerical array indexing because it's such a fertile ground for bugs. For
example, I find it really hard to look at:

var up = i-1>0 ? -1 + i : -1 + h;

...and tell if it's correct. I used a mod_wrap function instead, which is an
implementation of Python-like modulo, which 'wraps' negative numbers to the
top of the range.

