Skip to content

Improve naming in std types exercise - #3277

Open
fw-immunant wants to merge 1 commit into
google:mainfrom
fw-immunant:fw/hashmap-value-naming
Open

Improve naming in std types exercise#3277
fw-immunant wants to merge 1 commit into
google:mainfrom
fw-immunant:fw/hashmap-value-naming

Conversation

@fw-immunant

Copy link
Copy Markdown
Collaborator

This makes this exercise a bit cleaner and easier to follow.

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
fw-immunant force-pushed the fw/hashmap-value-naming branch from b2a8182 to d8a09d7 Compare September 11, 2026 19:30

@randomPoison randomPoison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I had one small suggestion but otherwise I think this is a good improvement.

Comment thread src/std-types/exercise.rs
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We count strings and characters in the other uses of Counter in main, so I think this is probably clear in context.

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.

2 participants