Improve naming in std types exercise - #3277
Open
fw-immunant wants to merge 1 commit into
Open
Conversation
the exercise used to call the map from values to their counts `values, but it maps *from* values to their counts. it is more aptly called `counts`. additionally, mapping from u32 to u64 in the initial monomorphic implementation make it less than obvious which integer type is the type of the values being counted and which integer type is the count itself. switch the type initially being counted to char to remove this ambiguity. finally, do not use `value` as the variable name for the individual values of the type being counted. though this is technically accurate, it is an unfortunate collision with the fact that hash maps are a key-value data structure, and in this case the keys of the hash map are the values being counted, while its values are the per-value counts. instead, we count "item"s.
fw-immunant
force-pushed
the
fw/hashmap-value-naming
branch
from
September 11, 2026 19:30
b2a8182 to
d8a09d7
Compare
randomPoison
approved these changes
Sep 11, 2026
randomPoison
left a comment
Contributor
There was a problem hiding this comment.
Looks good! I had one small suggestion but otherwise I think this is a good improvement.
Comment on lines
+55
to
+61
| let mut intctr = Counter::new(); | ||
| intctr.count(13); | ||
| intctr.count(14); | ||
| intctr.count(16); | ||
| intctr.count(14); | ||
| intctr.count(14); | ||
| intctr.count(11); |
Contributor
There was a problem hiding this comment.
Maybe it'd better to not use ints as the thing we're counting? At least I think it's a little confusing since there's the number we're counting and then the number of times we've seen that number. Maybe have this one count strings instead?
Collaborator
Author
There was a problem hiding this comment.
We count strings and characters in the other uses of Counter in main, so I think this is probably clear in context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes this exercise a bit cleaner and easier to follow.