News for hackers. Stuff that matters.
Re:A Readable Conway's Game of Life by ihodes on Sunday April 22, 2012 @08:16PM (#3876631)
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.

Re:A Readable Conway's Game of Life by gsabo on Sunday April 22, 2012 @08:42PM (#3876685)
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.
Re:A Readable Conway's Game of Life by agentultra on Sunday April 22, 2012 @11:32PM (#3877089)
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... 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. :)

Re:A Readable Conway's Game of Life by gsabo on Monday April 23, 2012 @12:46AM (#3877273)
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.
Re:A Readable Conway's Game of Life by fsiefken on Sunday April 22, 2012 @09:25PM (#3876780)
Reminds me of an even more reabable coffeescript example posted a year ago on HN: http://willbailey.name/conway/docs/conway.html
Re:A Readable Conway's Game of Life by losvedir on Sunday April 22, 2012 @08:57PM (#3876720)
And, conversely, an unreadable Game of Life in one line of APL (with explanation): http://www.youtube.com/watch?v=a9xAKttWgP4
Re:A Readable Conway's Game of Life by robomartin on Sunday April 22, 2012 @09:56PM (#3876855)
What do you mean? It's perfectly readable if you know APL.
Re:A Readable Conway's Game of Life by prezjordan on Sunday April 22, 2012 @09:10PM (#3876751)
I wish I could find videos like this but with J.
Re:A Readable Conway's Game of Life by wollw on Monday April 23, 2012 @12:36AM (#3877237)
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

Re:A Readable Conway's Game of Life by jastanton_ on Sunday April 22, 2012 @08:31PM (#3876658)
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.

Re:A Readable Conway's Game of Life by gsabo on Sunday April 22, 2012 @09:12PM (#3876755)
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.

Re:A Readable Conway's Game of Life by ertdfgcb on Monday April 23, 2012 @12:43AM (#3877258)
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/

Re:A Readable Conway's Game of Life by huhtenberg on Sunday April 22, 2012 @08:29PM (#3876651)
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.
Re:A Readable Conway's Game of Life by dethstarr on Monday April 23, 2012 @12:24AM (#3877207)
Good job. I enjoyed looking at the output from an artistic point of view.
Re:A Readable Conway's Game of Life by wsbail29 on Sunday April 22, 2012 @08:05PM (#3876615)
nice implementation! The color adds a lot of visual interest. Here's my monochrome implementation.

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

Re:A Readable Conway's Game of Life by jlarocco on Sunday April 22, 2012 @08:21PM (#3876639)
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.

Re:A Readable Conway's Game of Life by gsabo on Sunday April 22, 2012 @09:03PM (#3876734)
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.