Live data from Hacker News

Conway's Game of Life in CoffeeScript

willbailey.name

1–10 of 23 posts

Re: Conway's Game of Life in CoffeeScript

#4
post #2

I've been playing around with CoffeeScript and docco a bit lately and I thought I'd share this little project. Thanks to Jeremy Ashkenas for creating these fantastic tools.

Nice code!

Docco always impresses too, eh?

I really like the use of:

this[key] = value for key, value of options

I'm going to use that for sure :)

Re: Conway's Game of Life in CoffeeScript

#6
Pretty clean code! A small suggestion:

  cell.live = false if count  3
  cell.live = true  if count == 3
Could become:

  cell.live = count  3
  cell.live = count == 3
since it's a bit redundant to write "true" since it's already a boolean expression. It's a little bit like saying:

  if a == true:
    return true
  else:
    return false
instead of:

  return a // Agreed that a could be a "truth" value without being the real "true". Still:

  return !!a // With a hack

Re: Conway's Game of Life in CoffeeScript

#7
post #6

Pretty clean code! A small suggestion: cell.live = false if count 3 cell.live = true if count == 3 Could become: cell.live = count 3 cell.live = count == 3 since it's a bit redundant to write "true" since it's already a boolean expression. It's a little bit like saying: if a == true: return true else: return false instead of: return a // Agreed that a could be a "truth" value without being the real "true". Still: ret…

Or simply:

    cell.live = count is 3
no?

Re: Conway's Game of Life in CoffeeScript

#8
post #5

Be sure to check out the annotated source - http://willbailey.name/conway/docs/conway.html

I really like how that is done. It would be great to be able to annotate source code like this within your IDE.

Looks like it was created using Docco - http://jashkenas.github.com/docco/

Re: Conway's Game of Life in CoffeeScript

#9
post #5

Be sure to check out the annotated source - http://willbailey.name/conway/docs/conway.html

I really like how that is done. It would be great to be able to annotate source code like this within your IDE.

the newest version of vim has this seamlessly integrated :)

Re: Conway's Game of Life in CoffeeScript

#10
post #6

Pretty clean code! A small suggestion: cell.live = false if count 3 cell.live = true if count == 3 Could become: cell.live = count 3 cell.live = count == 3 since it's a bit redundant to write "true" since it's already a boolean expression. It's a little bit like saying: if a == true: return true else: return false instead of: return a // Agreed that a could be a "truth" value without being the real "true". Still: ret…

Or simply: cell.live = count is 3 no?

No. You aren't handling the case when count is 2 correctly. In that case, cell.live should remain unchanged, while you are setting it to false. (Note, however, that the code in the comment you are replying to is also incorrect. And does the same thing as your code. So you posted a correct transformation of incorrect code, that keeps it incorrect.)
Post reply on HN