Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose/expectation of the first struct koan is unclear #286

Open
cincodenada opened this issue Dec 4, 2023 · 1 comment
Open

Purpose/expectation of the first struct koan is unclear #286

cincodenada opened this issue Dec 4, 2023 · 1 comment

Comments

@cincodenada
Copy link

cincodenada commented Dec 4, 2023

Hello, I am running through the koans as my introduction to Elixir, and so far it's been quite nice! I'm a bit confused as to what the purpose of the first structs koan is:

  koan "Structs are defined and named after a module" do
    person = %Person{}
    assert person == ___
  end

I started with %{name: nil, age: nil} which of course told me that it wasn't a Structs.Person, so I went with %Person{name: nil, age: nil} which worked, as does %Person{} which...I guess demonstrates that struct equality is based on membership rather than (what I would call) instances? And actually I just went back and discovered that it is even threequal, which is unexpected!

Perhaps this first koan should be something about member equality? It just felt out of step with the rest of the koans to this point, which were pretty clear about what they were demonstrating and what I was expected to fill it in with.

(For context, I'm a fairly experienced developer who spends most of my time in things like Javascript and Python but have wandered far afield, I've enjoyed Rust and Racket and bounced off of Haskell a while back)

@iamvery
Copy link
Collaborator

iamvery commented Dec 5, 2023

Hey there, Ell. This is great feedback! As I'm looking at it, I too don't quite know the purpose of this koan. It may have been a "stretch" at making the point of the description, but the example itself isn't doing a good job making that point.

A couple ideas come to mind, but I'm not sure I like any them... One would be to dip into the nitty gritty with an assertion like:

assert person.__struct__ == ___

I don't love this option, because the __struct__ detail is not very important and would be mostly a distraction to introduce so early.

Another option might be to adjust the description to something like "Structs are map-like data defined and named after a module" along with:

assert is_map(person)

But again I'm not sure that's really helpful and the map-like behavior is revealed in a later koan.

Curious, based on your experience with going through these with fresh eyes, might there have been a way you would have liked to be introduced to structs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants