クラス名を考える
プログラミングにおいて命名は重要な要素ですが、絶対的な正解があるとは限らない分野でもあります。
命名に関する情報は書籍やネットでも多くありますが、特に設計やレビューなどで人と話し合うとき、個人感覚だけだと、その経験や考え方に左右され、他の人には納得しづらい命名になることもありえます。
そこで今回は参考の一つとして採用実績を一つの指標と出来るよう、標準APIやフレームワーク、ライブラリなどで使用されているクラスの命名をランキングにしてみました。
ランキング
Java SE 8
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Basic | 77 | Exception | 434 |
2 | J | 67 | UI | 172 |
3 | Metal | 54 | Helper | 129 |
4 | Abstract | 52 | Event | 83 |
5 | Default | 51 | Listener | 79 |
6 | Invalid | 51 | Factory | 75 |
7 | Key | 48 | Type | 66 |
8 | Synth | 48 | Holder | 64 |
9 | File | 46 | Stream | 63 |
10 | Xml | 44 | Handler | 50 |
11 | Dyn | 40 | Context | 49 |
12 | Object | 37 | Info | 48 |
13 | Multi | 35 | Operations | 48 |
14 | XML | 34 | Model | 46 |
15 | Accessible | 28 | Spec | 44 |
16 | M | 26 | View | 39 |
17 | SOAP | 26 | Manager | 36 |
18 | Image | 26 | Provider | 36 |
19 | Job | 25 | Error | 36 |
20 | Data | 25 | Set | 35 |
21 | 24 | Permission | 33 | |
22 | Attribute | 23 | Border | 33 |
23 | Service | 23 | Spi | 30 |
24 | SQL | 22 | Action | 29 |
25 | Row | 22 | Bean | 29 |
26 | No | 22 | Key | 28 |
27 | Type | 22 | Map | 26 |
28 | Name | 22 | Resource | 26 |
29 | Bean | 22 | Support | 25 |
30 | String | 21 | Channel | 25 |
31 | SSL | 21 | Value | 25 |
32 | Not | 21 | Impl | 25 |
33 | Long | 20 | Policy | 25 |
34 | Simple | 20 | Filter | 24 |
35 | Cert | 20 | Element | 24 |
36 | Illegal | 20 | Object | 23 |
37 | Servant | 19 | List | 23 |
38 | Input | 19 | Name | 23 |
39 | DOM | 18 | Attribute | 22 |
40 | Text | 18 | Adapter | 21 |
41 | IIO | 18 | Result | 21 |
42 | Double | 18 | Writer | 20 |
43 | Naming | 18 | Source | 20 |
44 | Unknown | 18 | Stub | 19 |
45 | Policy | 18 | Reader | 19 |
46 | Printer | 18 | Function | 18 |
47 | Document | 17 | Constants | 18 |
48 | Binding | 17 | Service | 16 |
49 | Web | 17 | Queue | 15 |
50 | RMI | 17 | Reference | 15 |
51 | Menu | 16 | Layout | 14 |
52 | Date | 16 | Format | 14 |
53 | Event | 16 | Editor | 14 |
54 | Certificate | 16 | Data | 13 |
55 | Element | 16 | Iterator | 13 |
56 | Thread | 16 | Pane | 13 |
57 | Tree | 16 | Entry | 12 |
58 | Server | 15 | Delegate | 12 |
59 | X | 15 | Mode | 12 |
60 | JMX | 15 | Callback | 12 |
61 | Open | 14 | Control | 12 |
62 | Table | 14 | Buffer | 12 |
63 | Socket | 13 | Icon | 11 |
64 | List | 13 | Formatter | 11 |
65 | Midi | 13 | Parameters | 11 |
66 | Atomic | 13 | Field | 11 |
67 | Int | 13 | Descriptor | 11 |
68 | Component | 12 | Style | 10 |
69 | Mouse | 12 | Consumer | 10 |
70 | Property | 12 | Connection | 10 |
71 | Class | 12 | Binding | 10 |
72 | Media | 12 | Operator | 10 |
73 | Relation | 12 | Time | 10 |
74 | Doc | 12 | Resolver | 10 |
75 | Activation | 12 | Notification | 9 |
76 | Value | 12 | Component | 9 |
77 | HTML | 12 | Op | 9 |
78 | EC | 11 | Document | 9 |
79 | Standard | 11 | Supported | 9 |
80 | Drag | 11 | Attributes | 9 |
81 | IOR | 11 | Method | 9 |
82 | Unsupported | 11 | Painter | 9 |
83 | Adapter | 11 | Proxy | 9 |
84 | RSA | 11 | Table | 9 |
85 | Border | 11 | Builder | 9 |
86 | Stream | 11 | Ref | 8 |
87 | Memory | 10 | Lock | 8 |
88 | Audio | 10 | Option | 8 |
89 | Styled | 10 | Array | 8 |
90 | URL | 10 | Node | 8 |
91 | Style | 10 | Renderer | 8 |
92 | LS | 10 | Date | 8 |
93 | Current | 10 | Button | 8 |
94 | Line | 10 | Syntax | 8 |
95 | Color | 10 | Param | 8 |
96 | Number | 10 | Selector | 8 |
97 | Acl | 9 | Location | 8 |
98 | URI | 9 | Visitor8 | 8 |
99 | DSA | 9 | Visitor6 | 8 |
100 | Array | 9 | Visitor7 | 8 |
Java EE 7
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Html | 62 | Exception | 215 |
2 | Message | 44 | Context | 70 |
3 | Xml | 42 | Listener | 62 |
4 | UI | 29 | Type | 60 |
5 | SOAP | 28 | Event | 53 |
6 | Web | 27 | Factory | 53 |
7 | Servlet | 27 | Handler | 43 |
8 | Client | 27 | Holder | 32 |
9 | Http | 26 | Keys | 31 |
10 | Json | 25 | Wrapper | 30 |
11 | Connection | 22 | Stats | 24 |
12 | Transaction | 21 | Term | 23 |
13 | Tag | 21 | Resolver | 23 |
14 | JMS | 20 | Converter | 20 |
15 | Resource | 20 | Builder | 20 |
16 | Constraint | 18 | Info | 18 |
17 | EJB | 16 | Manager | 18 |
18 | Faces | 16 | Tag | 18 |
19 | Pre | 16 | Config | 18 |
20 | Abstract | 16 | Provider | 17 |
21 | Entity | 15 | Node | 16 |
22 | Persistence | 15 | Message | 16 |
23 | Validation | 14 | Descriptor | 15 |
24 | Post | 14 | Validator | 15 |
25 | Server | 13 | Target | 14 |
26 | Jsp | 13 | Connection | 14 |
27 | Method | 13 | Element | 14 |
28 | Managed | 13 | Bean | 14 |
29 | View | 13 | Adapter | 13 |
30 | Session | 13 | Scoped | 13 |
31 | Process | 12 | Callback | 12 |
32 | Not | 12 | Attribute | 12 |
33 | XA | 12 | Param | 11 |
34 | Work | 12 | Expression | 11 |
35 | Named | 12 | Result | 11 |
36 | Job | 12 | Mode | 11 |
37 | Map | 11 | Object | 11 |
38 | Flow | 11 | Binding | 10 |
39 | Service | 11 | Stream | 10 |
40 | EL | 10 | Service | 10 |
41 | Application | 10 | Data | 10 |
42 | Invalid | 10 | Session | 10 |
43 | No | 10 | Query | 9 |
44 | Validator | 10 | Request | 9 |
45 | Bean | 10 | Model | 9 |
46 | Mime | 9 | Column | 9 |
47 | JAXB | 9 | Part | 8 |
48 | Action | 9 | Permission | 8 |
49 | Criteria | 9 | Impl | 8 |
50 | Queue | 8 | Support | 8 |
51 | Parameter | 8 | Definition | 8 |
52 | Deployment | 8 | Response | 8 |
53 | Value | 8 | Link | 7 |
54 | Annotated | 8 | Definitions | 7 |
55 | Behavior | 8 | Parameter | 7 |
56 | Response | 8 | Endpoint | 7 |
57 | Facelet | 7 | Writer | 7 |
58 | Async | 7 | Status | 6 |
59 | Topic | 7 | Method | 6 |
60 | Attribute | 7 | Delegate | 6 |
61 | Context | 7 | Join | 6 |
62 | Partition | 7 | Value | 6 |
63 | Provider | 7 | Configuration | 6 |
64 | Converter | 7 | Feature | 6 |
65 | Handler | 7 | Statistic | 6 |
66 | Exception | 7 | Filter | 6 |
67 | Query | 6 | Home | 5 |
68 | Path | 6 | Address | 5 |
69 | State | 6 | Property | 5 |
70 | Private | 6 | Transaction | 5 |
71 | Folder | 6 | Mapper | 5 |
72 | Property | 6 | Container | 5 |
73 | Result | 6 | Base | 5 |
74 | Visit | 6 | Scope | 5 |
75 | Auth | 6 | Servlet | 5 |
76 | Item | 6 | Table | 5 |
77 | Local | 6 | Source | 5 |
78 | Illegal | 6 | Path | 4 |
79 | Type | 6 | Execution | 4 |
80 | Generic | 6 | Form | 4 |
81 | Data | 6 | Root | 4 |
82 | External | 5 | Id | 4 |
83 | Byte | 5 | Reader | 4 |
84 | Join | 5 | Registration | 4 |
85 | Expression | 5 | Timeout | 4 |
86 | Remote | 5 | Consumer | 4 |
87 | Body | 5 | Header | 4 |
88 | Endpoint | 5 | Constraint | 4 |
89 | Header | 5 | Renderer | 4 |
90 | After | 5 | Interceptor | 4 |
91 | Fetch | 5 | Registry | 4 |
92 | Container | 5 | Reference | 4 |
93 | Partial | 5 | Attributes | 4 |
94 | Element | 5 | Behavior | 4 |
95 | Request | 5 | Resource | 4 |
96 | Registry | 5 | Producer | 4 |
97 | Filter | 5 | Entity | 3 |
98 | Policy | 5 | Util | 3 |
99 | Navigation | 5 | String | 3 |
100 | Store | 4 | Instance | 3 |
Spring Framework 4.2.4
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Abstract | 238 | Exception | 258 |
2 | Simple | 88 | Resolver | 161 |
3 | Default | 81 | Factory | 125 |
4 | Bean | 75 | Utils | 114 |
5 | Web | 73 | Bean | 111 |
6 | Mock | 68 | Handler | 110 |
7 | Spring | 50 | Source | 88 |
8 | Request | 45 | Interceptor | 73 |
9 | Resource | 43 | Context | 72 |
10 | Message | 43 | Adapter | 61 |
11 | Http | 42 | Converter | 52 |
12 | Transaction | 41 | Support | 51 |
13 | Servlet | 41 | Processor | 47 |
14 | Method | 40 | Manager | 43 |
15 | Annotation | 39 | View | 43 |
16 | Hibernate | 38 | Tag | 38 |
17 | Jms | 35 | Parser | 37 |
18 | Sql | 33 | Editor | 37 |
19 | Generic | 33 | Listener | 36 |
20 | Property | 31 | Request | 36 |
21 | Handler | 30 | Loader | 36 |
22 | Aspect | 27 | Filter | 35 |
23 | Portlet | 27 | Accessor | 35 |
24 | Standard | 26 | Registry | 34 |
25 | Delegating | 25 | Strategy | 34 |
26 | Async | 25 | Configurer | 33 |
27 | Local | 24 | Configuration | 32 |
28 | Session | 24 | Provider | 32 |
29 | Cache | 23 | Builder | 30 |
30 | Context | 20 | Mapping | 29 |
31 | Managed | 20 | Callback | 26 |
32 | Stomp | 19 | Definition | 24 |
33 | J | 18 | Executor | 24 |
34 | Configurable | 18 | Advisor | 23 |
35 | Type | 18 | Creator | 23 |
36 | Remote | 17 | Holder | 23 |
37 | Model | 17 | Exporter | 22 |
38 | Jndi | 16 | Operations | 22 |
39 | Sock | 16 | Resource | 22 |
40 | Xml | 16 | Aware | 22 |
41 | M | 15 | Type | 20 |
42 | Smart | 15 | Template | 20 |
43 | Op | 15 | Registration | 20 |
44 | Open | 15 | Message | 20 |
45 | Class | 15 | Session | 20 |
46 | Simp | 15 | Extractor | 19 |
47 | Response | 15 | Advice | 19 |
48 | Mapping | 14 | Event | 18 |
49 | Invalid | 14 | Proxy | 18 |
50 | Connection | 14 | Incrementer | 17 |
51 | Script | 14 | Matchers | 17 |
52 | Enable | 13 | Controller | 17 |
53 | Concurrent | 13 | Value | 16 |
54 | Data | 13 | Matcher | 15 |
55 | Date | 13 | Comparator | 15 |
56 | Test | 12 | Condition | 15 |
57 | Application | 12 | Helper | 15 |
58 | Aop | 12 | Operation | 15 |
59 | Composite | 12 | Generator | 14 |
60 | Proxy | 12 | Info | 14 |
61 | Custom | 12 | Reference | 14 |
62 | Task | 11 | Config | 14 |
63 | Destination | 11 | Response | 14 |
64 | View | 11 | Registrar | 13 |
65 | Content | 11 | Pointcut | 13 |
66 | User | 11 | Result | 13 |
67 | Spel | 11 | Formatter | 13 |
68 | Velocity | 11 | Translator | 12 |
69 | Commons | 10 | Initializer | 12 |
70 | Reflective | 10 | Attribute | 12 |
71 | Caching | 10 | Map | 12 |
72 | No | 10 | Status | 11 |
73 | Jdbc | 10 | Metadata | 11 |
74 | Groovy | 10 | Reader | 11 |
75 | Persistence | 9 | Attributes | 11 |
76 | Path | 9 | Service | 11 |
77 | Mime | 9 | Scope | 10 |
78 | Url | 9 | Weaver | 10 |
79 | Static | 9 | Assembler | 10 |
80 | Object | 9 | Synchronization | 9 |
81 | Named | 9 | Mapper | 9 |
82 | String | 8 | Decorator | 9 |
83 | Embedded | 8 | Mode | 9 |
84 | Uri | 8 | Wrapper | 8 |
85 | Scheduled | 8 | Method | 8 |
86 | Expression | 8 | Entry | 8 |
87 | Jasper | 8 | Parameter | 8 |
88 | Free | 8 | Container | 8 |
89 | Properties | 8 | Literal | 8 |
90 | Yaml | 8 | Cache | 8 |
91 | Cannot | 8 | Locator | 8 |
92 | Cors | 8 | Selector | 8 |
93 | Jta | 7 | Marshaller | 8 |
94 | Advisor | 7 | Expression | 8 |
95 | Parameter | 7 | Lookup | 8 |
96 | Reflection | 7 | Client | 8 |
97 | Listenable | 7 | Environment | 8 |
98 | Map | 7 | Transport | 7 |
99 | Rmi | 7 | Chain | 7 |
100 | Locale | 7 | Visitor | 7 |
Apache Tomcat 8
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Abstract | 65 | Factory | 56 |
2 | Ast | 43 | Constants | 45 |
3 | Constants | 42 | Handler | 34 |
4 | Jsp | 30 | Listener | 33 |
5 | File | 27 | Base | 33 |
6 | Ws | 25 | Exception | 33 |
7 | Standard | 23 | Element | 32 |
8 | Context | 20 | Filter | 32 |
9 | SSI | 19 | Task | 31 |
10 | EL | 18 | Impl | 30 |
11 | Nio | 18 | Set | 27 |
12 | Jar | 15 | Stream | 26 |
13 | JMX | 14 | SF | 23 |
14 | Store | 13 | Bean | 23 |
15 | Ajp | 13 | Manager | 21 |
16 | Extended | 13 | Valve | 20 |
17 | Cluster | 13 | Config | 19 |
18 | Pojo | 13 | Context | 18 |
19 | Channel | 13 | Buffer | 18 |
20 | Async | 12 | Processor | 17 |
21 | Class | 12 | Util | 15 |
22 | Request | 11 | Pool | 15 |
23 | Base | 11 | Info | 15 |
24 | Apr | 10 | Wrapper | 15 |
25 | Naming | 10 | Rule | 15 |
26 | Message | 10 | Sender | 14 |
27 | Session | 10 | Interceptor | 14 |
28 | Pool | 9 | Utils | 12 |
29 | Application | 9 | Servlet | 12 |
30 | Default | 9 | Resource | 12 |
31 | SSL | 9 | Entry | 11 |
32 | Lifecycle | 9 | Parser | 11 |
33 | Security | 9 | Message | 11 |
34 | Web | 9 | Source | 11 |
35 | Resource | 9 | Data | 11 |
36 | User | 9 | Ref | 10 |
37 | Memory | 8 | State | 10 |
38 | Set | 8 | Cache | 10 |
39 | Tld | 8 | Callback | 10 |
40 | Rewrite | 8 | Realm | 10 |
41 | Constant | 8 | Type | 10 |
42 | Remote | 8 | Channel | 10 |
43 | Comet | 8 | Loader | 10 |
44 | Internal | 8 | Map | 9 |
45 | Pooled | 8 | Protocol | 8 |
46 | Tag | 8 | Event | 8 |
47 | Generic | 8 | Expression | 7 |
48 | Data | 8 | Value | 7 |
49 | Instance | 7 | Authenticator | 7 |
50 | Byte | 7 | Support | 7 |
Apache Commons Lang 3.4
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Mutable | 11 | Utils | 32 |
2 | Char | 6 | Builder | 9 |
3 | Str | 5 | Initializer | 8 |
4 | Concurrent | 4 | Exception | 7 |
5 | Date | 4 | Translator | 4 |
6 | Diff | 3 | Unescaper | 3 |
7 | Numeric | 3 | Escaper | 3 |
8 | Unicode | 3 | Triple | 3 |
9 | Class | 3 | Format | 3 |
10 | Fast | 3 | Style | 3 |
Google Guava
順位 | Prefix | 出現回数 | Suffix | 出現回数 |
---|---|---|---|---|
1 | Forwarding | 36 | Map | 22 |
2 | Immutable | 34 | Multimap | 16 |
3 | Abstract | 17 | Future | 12 |
4 | Hash | 6 | Multiset | 11 |
5 | Byte | 6 | Service | 10 |
6 | Char | 6 | Set | 9 |
7 | Multimap | 6 | Cache | 8 |
8 | Tree | 6 | Table | 7 |
9 | Cache | 6 | Builder | 7 |
10 | Cycle | 5 | Stream | 7 |
11 | Map | 5 | Iterator | 7 |
12 | Finalizable | 5 | Exception | 7 |
13 | Array | 5 | Escaper | 6 |
14 | Unsigned | 5 | Map.Builder | 6 |
15 | Type | 4 | Queue | 5 |
16 | Removal | 4 | Math | 4 |
17 | Class | 4 | Escapers | 4 |
18 | Enum | 3 | Limiter | 4 |
19 | Sorted | 3 | Reference | 4 |
20 | Listenable | 3 | Supplier | 3 |
ランキングを支える技術
このランキングはJavaを使って、公開されているJavadocからHttpアクセスで一覧を取得し、変換、集計、ソート、マークダウン出力を行っています。
そのため、Javadocが公開されていれば、同じようにランキングが作成できます。
Ranking.java
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.IntStream;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.*;
public class Ranking {
public static void main(String[] args) {
Stream.<Triple<String, String, Integer>>of(
new Triple<>("Java SE 8", "http://docs.oracle.com/javase/8/docs/api", 100),
new Triple<>("Java EE 7", "http://docs.oracle.com/javaee/7/api", 100),
new Triple<>("Spring Framework 4.2.4", "http://docs.spring.io/spring/docs/current/javadoc-api", 100),
new Triple<>("Apache Tomcat 8", "http://tomcat.apache.org/tomcat-8.0-doc/api", 50),
new Triple<>("Apache Commons Lang 3.4", "https://commons.apache.org/proper/commons-lang/javadocs/api-3.4", 10),
new Triple<>("Google Guava 19", "http://docs.guava-libraries.googlecode.com/git/javadoc", 20))
.map(Ranking::create)
.forEach(Ranking::output);
}
static Triple<String, List<List<Map.Entry<String, Long>>>, Integer> create(Triple<String, String, Integer> p) {
return new Triple<>(p.l, Arrays.asList(get(p.m, t -> t[0]), get(p.m, t -> t[t.length - 1])), p.r);
}
static List<Map.Entry<String, Long>> get(String url, Function<String[], String> target) {
try {
return Jsoup.connect(url + "/allclasses-frame.html").get()
.select(".indexContainer li")
.stream()
.map(Element::text)
.map(t -> t.split("(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z])"))
.map(target)
.collect(groupingBy(identity(), counting()))
.entrySet()
.stream()
.sorted(Map.Entry.<String, Long>comparingByValue().reversed())
.collect(toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static void output(Triple<String, List<List<Map.Entry<String, Long>>>, Integer> p) {
System.out.println(String.format("## %s", p.l));
System.out.println("|順位|Prefix|出現回数|Suffix|出現回数|");
System.out.println("|:--|:--|:--|:--|:--|");
IntStream.range(0, p.r).forEach(i -> System.out.println(String.format("|%d|%s|%s|%s|%s|", i + 1,
p.m.get(0).get(i).getKey(), p.m.get(0).get(i).getValue(),
p.m.get(1).get(i).getKey(), p.m.get(1).get(i).getValue())));
}
static class Triple<L,M,R> {
L l;
M m;
R r;
Triple(L l, M m, R r) {
this.l = l;
this.m = m;
this.r = r;
}
}
}
あと、ざっくり作ったのでバグがあるかもしれません。もしも間違っているようなら、修正リクエストをもらえると助かりますw
注意事項
- ランキングは件数で区切っているため、同じ出現回数の単語でもラインキング外になっている場合があります。
- クラス名が単一の単語(String, Integerなど)の場合は、Prefix、Suffix双方としてカウントされます。