elixir-koans icon indicating copy to clipboard operation
elixir-koans copied to clipboard

Add another `assert` to Agent "maintain state" koan

Open jordan-brough opened this issue 7 years ago • 6 comments

To clarify/emphasize that this is a persistent state.

jordan-brough avatar Mar 27 '18 15:03 jordan-brough

When I first saw the code it wasn't 100% clear to me whether the result was a one-time thing or not. I wrote this extra test to confirm to myself that the state would remain persistently, and thought perhaps it would be a helpful thing to have by default.

jordan-brough avatar Mar 27 '18 15:03 jordan-brough

Hmm ya, I see what you mean. I feel like even this example might lead the learner to believe that the function is executed each time rather than being a producer of the state. Do you think a later example that shows how the state can be updated serves to solidify that better than a repeated assertion?

Thoughts @felipesere ?

iamvery avatar Mar 27 '18 15:03 iamvery

For me this koan was confusing because the text said "maintain state, so you can ask them about it" but the example only queried a single time so the persistence wasn't clear. Especially coming fresh from the previous Processes and Tasks modules (where messages and responses are one-time events) this aspect was confusing to me initially. It would be nice to have something that clears that up imo. The later examples do but I was confused about that initially.

jordan-brough avatar Mar 27 '18 16:03 jordan-brough

Thank you @jordan-brough for opening this PR 👍

Should we maybe connect this Koan somehow with one where we explicitly mutate the state? Its kinda hard to prove that the state won't change. Looking at it now (having done a bunch of Elixir since the Koans) it feels natural that nothing changes unless instructed to do so. Maybe your connection to processes and messages also gives us a clue? Maybe we can make the difference more explicit?

@iamvery I also feel we could extract the function in start_link itself into something like one_off_producer = fn -> state end and lift state into its own variable?

felipesere avatar Mar 27 '18 22:03 felipesere

@felipesere i like that! let the code communicate that intent 💪

iamvery avatar Mar 28 '18 12:03 iamvery

Sounds good! I'll take a stab at refactoring along those lines. Thanks.

jordan-brough avatar Mar 28 '18 13:03 jordan-brough