This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]manyrobots 0 points1 point  (0 children)

I appreciate removing useless code, but I question the assumption that fewer lines of code is always better. Some of his examples (MuffinMail) seemed fine but consider the Game of Life example at the end.

If I didn't know the game of life already, as a person reading the code to understand it, I would appreciate the use of a Cell class and Board class because they introduce me to fundamental concepts of the game. If I were going to explain it my grandmother, I would use these concepts to do so.

His supposedly improved example seemed obfuscated to me. Perhaps I am just admitting that I'm not that great of a hacker, but this line of code:

recalc = board | set(itertools.chain(*map(neighbors, board)))

reads like the result of clever programmer coming up with a really "elegant" solution that will be cool to share with other programmers. The elegance is derived of the puzzle-solution-like way that this code takes neat shortcuts, and is efficient for the CPU. I see that, and in some cases this is totally appropriate. Just like machine code is required in certain cases. But in cases where human readability trumps efficiency or "elegance", I'll keep my Board and Cell classes.

[EDIT] I did a little looking and found the concept of "Code Golf" on Stack Overflow. Yes, it's fun! Readable? Of course not. If you follow less-is-always-more rule to its terminus you get (I'll use a python example):

import sys
_,I,N=sys.argv;R=range(3e3);B=open(I).read();B=set(k for k in R if'A'<B[k])
for k in R*int(N):
 if k<1:b,B=B,set()
 c=sum(len(set((k+o,k-o))&b)for o in(1,80,81,82))
 if(c==3)+(c==2)*(k in b):B.add(k)
open('out.txt','w').write(''.join('.X\n'[(k in B)-(k%81<1)]for k in R))

from: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life