views:

150

answers:

3

I have a java.util.Map that maps from a logical name to a set of parameters to use with that name.

Map<String,Parameters> howShouldINameThee = ...;

What is the best name for this map?

Should I go simple and just call this parameters or parametersMap?

Do I include information about the key in the name like paramtersByName so that how to use the String key is more obvious?

+3  A: 

I tend toward something like parametersByName to leave no confusion about what the contents of the Map are. You never know when you're going to have to revisit code that you haven't looked at in a long time.

In Java, I find it unnecessary to include the name of the data structure (like parametersByNameMap) since the typing is explicit.

danben
I agree. Be specific on the meaning of the variable, but don't include the type into the name.
Scarlet
+5  A: 

A Map maps something to something else.
I like to use names like uidToPerson. "To" being the shortest unambiguous way I can think of to show that I have a map.

Edit:
I'll add that I prefer to have the map named this way, because "key" and "value" appear in that order in the name. As opposed to valueByKey. In mapping operations, the key comes first. You put(key, value) or get(key) that gives a value.

Of course this is a matter of personal preference.

z5h
+1, I follow the `keyToValue` convention, too.
Jonathon
+1  A: 

In my apps there would be quite many types of parameters.

For example, in GAE, when I need to extract the http request parameters into a serializable form, I name the map httpRequestParameters or httpReqParams. sessionAttrs, for example.

For GWT RPC, client-to-server parameter hash, I would name it client2ServerParams or clnt2SrvrParms and name the counterpart server2clientParams or srvr2ClntParms.

In openid consumer, I would name the map, consumerAuthRequests or redirectFormParameters and its counterpart providerResponses.

In the map of reformatted input Main arguments, I would call it inputArgs.

In my cases, httpRequestParametersBy name, client2ServerParamsByName, consumerAuthRequestsByName, inputArgsByName, or inputArgValueByKey, etc would be redundant and too long because I would always know that the key of the map is a "name" anyway. I just make sure the name is plural to give me an inkling that it is a collection.

Exception to this practice is when the key is not a name but an object than I would name the map like vehicleByDriver, projByMgr, toxicFoodListByAnimal.

Blessed Geek