Do you name a dictionary by the key or the value? I have a dictionary that will hold gradient data and the component:
dictionary[gradient] = component;
Do I name it gradientDictionary or componentDictionary?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityDo you name a dictionary by the key or the value? I have a dictionary that will hold gradient data and the component:
dictionary[gradient] = component;
Do I name it gradientDictionary or componentDictionary?
That depends, but generally I'd suggest naming by the values. The keys are often just a way to quickly find what you are actually looking for and will be using.
Depending on context, for your specific example, I'd also probably suggest just calling the dictionary components
to avoid encoding too much type information in the name.
componentsByName[name]
and componentsByID[id]
. It will be visually clear when the wrong one is used, as the matching parts are next to each other: componentsByName[id]
.
componentByGradient