-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Ch8 edits after technical review #450
Conversation
To be fair, I have no experience with either Perl or Ruby and I've heard they both use "hash" to refer to unordered associative maps implemented using hashing. To reiterate: I am fine with only talking about |
From my POV this is wrong. Also, indexing gave a single byte back IIRC (because indexing gives back a reference that the compiler places an implicit deref on, to give you an lvalue, so |
Sadly, I agree. This is where |
So do you have a better way to explain why you can slice bytes of a str with |
@carols10cents We check that slices fall on complete UTF-8 sequences (which is I might be able to figure out where the actual decision was taken and the original arguments, if you want. |
Ok, I'm fine with adding "which is an implementation of the more general data structure called a map" or something, would that resolve this comment?
We do say:
so what if I change this to say "Each kind of collection has different capabilities and costs, and choosing an appropriate one for the situation you’re in is a skill you’ll develop over time. In this chapter, we’ll go over three collections which are used very often in Rust programs: [...] I think this will also make the discussion of "fundamental" moot? |
@carols10cents Both of those are great minimal changes, thank you! |
Slicing panics if you try and slice somewhere that isn't a character boundary. So why not allow indexing but panic if it's not a single byte character? I'd love to see the original discussion, I've tried to find it before and couldn't :-/ |
Oh, original issue for removing |
burntsushi says we should say:
|
Even for indexes pointing to single-byte characters, the
I like this but would change “do more work” to “be more specific.” |
Manishearth says:
&Manishearth> carols10cents: the expected workflow is "iterate via char_indices, then slice using indices you have noted down" &Manishearth> carols10cents: "It's rare to directly index/slice a string without iterating through it first. If iterating through it, you don't need to index; but you still need to form slices out of known char indices." nox> carols10cents: Make the string a bathtub full of water, explain that you can't get a single drop from it, only a section of the whole volume. |
nox> carols10cents: Please forget about the bathtub, |
So, I agree with @carols10cents on basically every point in the original post; I also agree with @eddyb in cases, but made the choices I did for the reasons that @carols10cents said. There's also a lot of other discussion here too, just wanted to finally actually mention that. |
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.
looks great, one extremely minor nit
nostarch/chapter08.md
Outdated
@@ -142,12 +142,12 @@ element past the end of the vector to be a fatal error that should crash the | |||
program. | |||
|
|||
When the `get` method is passed an index that is outside the array, it will | |||
return `None` without `panic!`ing. You would use this if accessing an element | |||
beyond the range of the vector will happen occasionally under normal | |||
return `None` without causing a `panic!` call. You would use this if accessing |
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 would remove "call" here, it feels weird to me, idk
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.
yeah i'm just trying to get rid of the word that's half code, half not code. what if i just change it to, all not code, "panicking"?
@steveklabnik i made a few more changes to actually resolve the discussions, want to take a look at the last commit or do you still approve? |
nostarch/chapter08.md
Outdated
with a range to create a string slice containing particular bytes: | ||
Because it's not clear what the return type of string indexing should be, and | ||
it is often a bad idea to index into a string, Rust dissuades you from doing so | ||
by asking you to be more specific if you really need it. The way you can me |
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/me/be/
@@ -1,7 +1,7 @@ | |||
|
|||
[TOC] | |||
|
|||
# Fundamental Collections | |||
# Common Collections |
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.
👍
Pretty small edits here.
@eddyb had some comments that I don't agree with, and I want to see what @steveklabnik thinks and discuss them in here, so I've pulled them out of the docx and linked to their context:
I think "hash map" is the term that will be most familiar to the most people from most languages, and it's also literally the name of the type. I think wanting to associate keys with values and be able to look them up by key is more fundamental than wanting a map that also does those things plus is sorted.
I think adding set to this chapter is too much, and I reach for these three WAY more often than I reach for a set.
The text I put here no longer makes sense to me either, which means I'm still confused. I think I was trying to contrast slicing to accessing an index: slicing doesn't have the expectation of performance that index access does, so even if it is fast, we aren't constrained by the expectation of performance like index access is, which is why it was taken away? I am still unsatisfied by this...
We decided we weren't going to do that unless they're under rust-lang or rust-lang-nursery and scheduled to have a 1.0 version by the time the book's printed.
Into_iter is too much complexity/distraction to introduce here, more than the type ending up being slightly different would.
The rest of your comments were excellent and I agree wholeheartedly, @eddyb! ❤️