39. 糟糕的註解 - 多餘的註解
• 含有開頭註解的簡單函式,讀這段註解可能比讀
這段程式更更花時間
1 // Utility method that returns when this.closed is true. Throws an exception
2 // if the timeout is reached.
3 public synchronized void waitForClose(final long timeoutMillis)
4 throws Exception
5 {
6 if (!closed) {
7 wait(timeoutMillis);
8 if(!closed)
9 throw new Exception ("MockResponseSender could not be closed");
10 }
11 }
40. 糟糕的註解 - 規定型註解
• 含有開頭註解的簡單函式,讀這段註解可能比讀
這段程式更更花時間
1 /**
2 *
3 * @param title The title of the CD
4 * @param author The author of the CD
5 * @param tracks The number of tracks on the CD
6 * @param durationInMinutes The duration of the CD in munutes
7 */
8 public void addCD(String title, String author, int tracks, int durationInMinutes)
9 {
10 CD cd = new CD();
11 cd.title = title;
12 cd.author = author;
13 cd.tracks = tracks;
14 cd.duration = durationInMinutes;
15 cdList.add(cd);
16 }
41. 糟糕的註解 - ⼲干擾型註解
• 沒有被⼲干擾到,真的嗎?
1 /*
2 * Default constructor.
3 */
4 protected AnnualDateRule() {}
5
6 /* The day of the month. */
7 private int dayOfMonth;
8
9 /*
10 * Return the day of the month.
11 *
12 * @return the day of the month.
13 */
14 public int getDatofMonth()
15 {
16 return dayOfMonth;
17 }
42. 當你可以使⽤用函式或者變數時就別
⽤用註解
1 // does the module from the global list<mod> depend on the
2 // subsystem we are part of?
3 if (semodule.getDependSubSystems().contains(subSysMod.getSubSystem())
4
5 ArrayList moduleDpendees = smodule.getDependSubSystems();
6 String outSubSystem = subSysMod.getSubSystem();
7 if (moduleDpendees.contains(ourSubSystem))