我应该如何命名java.util.Map? [英] How should I name a java.util.Map?
问题描述
我有一个java.util.Map
,它可以从逻辑名称映射到与该名称一起使用的一组参数.
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?
我是否应该简单地将其命名为parameters
或parametersMap
?
Should I go simple and just call this parameters
or parametersMap
?
我是否在名称中包含有关密钥的信息,例如paramtersByName
,以便更清楚地使用String
密钥?
Do I include information about the key in the name like paramtersByName
so that how to use the String
key is more obvious?
推荐答案
地图"将映射到其他映射.
我喜欢使用uidToPerson
之类的名称. 到"是我可以想到的最短的明确方法,可以证明我有一张地图.
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.
我还要补充一点,我更喜欢用这种方式命名地图,因为键"和值"在名称中按该顺序出现.与valueByKey
相反.在映射操作中,密钥位于第一位.您put(key, value)
或get(key)
给出了一个值.
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.
这篇关于我应该如何命名java.util.Map?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!