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

Explain multi-object for loops and range syntax #262

Closed
wants to merge 4 commits into from
Closed

Explain multi-object for loops and range syntax #262

wants to merge 4 commits into from

Conversation

Arya-Elfren
Copy link
Contributor

I think it makes more sense to actually explain what the range syntax means (other than just as an index generator) and that for loops can iterate over multiple things. Something to build an intuition so that people could come up with this code on their own if they needed to because they understand what a range is:

for (0..20, 3.., 9..) |_, _, _| {}

I've tried explaining it but I don't know if it works well, especially within the wider context of ziglings.

I don't know if it's better (or necessary) to explain mult-object for loops in a separate exercise and then introduce ranges in a different on (make exercise 17 about ranges in for loops and 16 just about multi-object)?

@chrboesch
Copy link
Collaborator

@Arya-Elfren Thanks. Did you see this: #261

@Arya-Elfren
Copy link
Contributor Author

No, I didn't. I just saw that exercise and thought it was probably an artifact of when we still had magical index captures and didn't explain the new concepts yet.

I definitely think we could use an extra exercise for multi-for loops but I don't know if it should be separated from the other ones like that?

Anyway, what should I do about this commit? Just leave it and wait for more feedback?

@ratfactor
Copy link
Owner

@Arya-Elfren Hmmm... yeah, let's just leave this open until I get a chance to post ex 100. There might be some overlap.

@Arya-Elfren
Copy link
Contributor Author

How easy is it to re-order exercises? (I haven't looked at build.zig in detail yet)
I think it would be odd to have multi-object for loops split from the rest of for loops. Especially if you basically already use them for the index exercise.

If we were doing exactly one concept per exercise I would do three (maybe four for overkill?) for loop exercises in a row:

  1. for loop: for (items) |item| {}
  2. range syntax: for (3..9) |n| {}
  3. multi for loop: for (items, others) |item, other| {}
    • Combining 2 and 3 to capture the index: for (items, 0..) |item, index| {} (introducing inferred end point)

@ratfactor
Copy link
Owner

Re-ordering is certainly possible, but would be...painful, especially since "Ex. XXX" references in GitHub issues would all suddenly be wrong.

You're right that the order is weird. If Ziglings were a book, it would be a total mess. But I think it's forgivable and maybe even kind of fun (to be charitable) to introduce concepts as Zig introduces them...

@ratfactor
Copy link
Owner

@Arya-Elfren
Copy link
Contributor Author

I feel like that's very comprehensive, I especially like ex95.

Other than the fact that they have to be separate (which is understandable) I think that's really good coverage.

@Arya-Elfren Arya-Elfren closed this May 3, 2023
@ratfactor
Copy link
Owner

Great, thanks for the feedback!

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

Successfully merging this pull request may close these issues.

None yet

3 participants