
Asynchronous Life, re-implementing Conways 'life' the async way - jacquesm
http://jacquesmattheij.com/asynchronous+life
======
diN0bot
somewhat off topic but...

this is a horrible fallacy:

> "I wrote some code, re-implementing life quick-and-dirty, in - yes, yuck -
> PHP. It's the tool of choice because it is very close in syntax to C and
> I've programmed lots of code in it so I can whip out something small like
> this in a couple of hours."

someone knows some dumb language and thinks he'll be more PRODUCTIVE in
another similar dumb language. familiarity gains very little compared to the
gains possible with a smart language, but which i mean one that makes the code
readable, less buggy and less horrendous.

as humans we're terrible at figuring out short and long term costs, as well as
comparing non-linear curves....

~~~
jacquesm
I'm not going to argue with you about my choice of tool, enough bits have been
spent arguing the pros and cons of various languages without getting anywhere.

But here's a challenge for you:

I've spent, start to finish less than 10 hour to code that, having the idea
(life cells that track time independently by counting generations) was 5
minutes, building it including breaks for dinner and a movie and a nightly
session to work out the kinks was 10 hours.

Clone it, in any other language that you care about, as long as the following
conditions are still met:

    
    
      - no fixed size world
    
      - uses the same principles
    
      - produces correct output (easy enough to verify, the
        'end' stable state of the f-pentomino minus the ejected
        gliders is easily checked)
    

You have this code for a reference, so you really only have to make a port, or
you can decide not to look at it and build it from scratch.

Report back how long it took and show the source. That way we can all learn
something because I'm really curious to see other implementations in other
languages.

edit: to make this clear, my 'hangup' had to do with the bit that creates new
cells on the fly, I was making them one generation older than the current one,
that was a tricky mistake, it seemed like the right thing to do, after all
then they could 'catch up' with the current crop and things would continue.

The reason that strategy backfires is that you potentially create a cell that
is older than the 2 generation 'window' that you can accommodate in this
scheme (because you only hold the state for the current and previous
generations in a cell).

It took me a long time to figure that out because I was very much convinced
the problem was elsewhere.

If I had chosen to use a statically allocated array of cells (more in line
with a hardware simulation) that would have never happened, so as always,
premature optimization is the root of all evil.

~~~
jules
I'd like to participate, and I don't want to look at your PHP. Can you
elaborate on what needs to be implemented?

Do I have this right:

\- use linked objects for the cells instead of an array

\- a method to bring a cell to the next generation, this method recursively
calls itself on the neighbors

\- live cells should be created on the fly, growing the "grid" (non
rectangular) as necessary

~~~
jacquesm
Almost, the recursion is only used when creating new cells, other than that it
is all simple iteration.

Basically the 'cell creation' is a shortcut used because I didn't want to
start off with a fixed size array of cells.

Each cell operates independently of its neighbours.

Nice to have a taker!

It's a small enough project that you can do it in a day and it is large enough
to get some insight into the various ways of solving things with different
languages.

I'm really curious what your code will look like and what language you will
write it in.

Please let me know when you're done, email in my profile.

~~~
jules
Ok, so the main loop is like

    
    
        for c in cells: c.update()
    

And update looks at the values of the neighbors and updates accordingly. Seems
straightforward, but I'm sure there will be pitfalls :)

I'm going to start in about 4 hours, I have other work to do now.

~~~
jacquesm
Yep, you got it.

