bslatkin / effectivepython

Effective Python: Second Edition — Source Code and Errata for the Book
https://effectivepython.com
2.24k stars 718 forks source link

item_57.py #107

Open zhubeilife opened 2 years ago

zhubeilife commented 2 years ago

I think there should only one game_logic here?

def game_logic(state, neighbors):
    # Do some blocking input/output in here:
    data = my_socket.recv(100)

def game_logic(state, neighbors):
    if state == ALIVE:
        if neighbors < 2:
            return EMPTY     # Die: Too few
        elif neighbors > 3:
            return EMPTY     # Die: Too many
    else:
        if neighbors == 3:
            return ALIVE     # Regenerate
    return state

and change to

def game_logic(state, neighbors):
    # Do some blocking input/output in here:
    data = my_socket.recv(100)
    if state == ALIVE:
        if neighbors < 2:
            return EMPTY     # Die: Too few
        elif neighbors > 3:
            return EMPTY     # Die: Too many
    else:
        if neighbors == 3:
            return ALIVE     # Regenerate
    return state
zhubeilife commented 2 years ago

oh It's not wrong, just a confused me.

bslatkin commented 4 months ago

Thank you for the report! I could see how it's confusing, yeah. I added a comment to the "fake" version with recv that explains its purpose. That will only show up in the example code, not in the book itself.