-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Rework iterator section #2523
Rework iterator section #2523
Conversation
for (int i = 0; i < array_len; i += 1) { | ||
int elem = array[i]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I put this PR up it occurs to me that we don't need to use C-style for
to demonstrate this concept, we could show the same thing in pure Rust:
let mut i = 0;
while i < array.len() {
let elem = array[i];
i += 1;
}
Might still be good to mention C-style for
in the speaker notes, since it's still a common point of reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda still feel like the C version is going to be clearer and more familiar for most students, tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djmitche Do you have an opinion here? I'm leaning towards leaving this as a c-style for
for readability and familiarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what, I'm going to leave it as a C-style for
but I'm going to add the rust equivalent in the speaker notes for easy reference. Let me know if you think that's a bad idea for whatever reason, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the C-style is fine.
- Add motivation slide. - Replace fibonacci example with slice iter example. - Add slide for iterator helper methods. - Reorder slides to talk about `collect` before `IntoIterator`. - Add additional speaker notes.
c162cfd
to
c66a766
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great improvement to this segment!
src/iterators/iterator.md
Outdated
impl<'a> Iterator for SliceIter<'a> { | ||
type Item = &'a i32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor detail, but I'd like to get away from the idea that all lifetimes are named 'a
-- maybe use 'sl
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 's
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
's
is good!
Co-authored-by: Dustin J. Mitchell <[email protected]>
Co-authored-by: Dustin J. Mitchell <[email protected]>
Co-authored-by: Dustin J. Mitchell <[email protected]>
This PR attempts to improve clarity and flow in the section on iterators. I don't think the current materials do a good job of motivating iterators or putting them in a context where students can understand them. This PR does the following to try to improve this:
for
loop to iterate over the contents of an array. This helps contextualize the concept of iteration in a way that most students will understand; Many languages have C-stylefor
loops, so students are likely going to be familiar with the syntax and will have seenfor (i = 0; i < len; i++)
many times.Iterator
. I also think this example is easier to understand than the fibonacci one, I found the logic there kind of confusing/hard to explain to students. It also demonstrates an iterator with a termination case, whereas the fibonacci example never terminates.Iterator
.collect
beforeIntoIterator
. I think this flows better after the slide on helper methods since this is just calling out a specific helper method.