在编写“库”类型类时,最好总是在 java 中编写标记文档(即 javadoc)还是假设代码可以是“自记录”的?例如,给定以下方法存根:
/**
* Copies all readable bytes from the provided input stream to the provided output
* stream. The output stream will be flushed, but neither stream will be closed.
*
* @param inStream an InputStream from which to read bytes.
* @param outStream an OutputStream to which to copy the read bytes.
* @throws IOException if there are any errors reading or writing.
*/
public void copyStream(InputStream inStream, OutputStream outStream) throws IOException {
// copy the stream
}
javadoc 似乎是不言而喻的,如果功能发生变化,只需要更新噪音。但是关于冲洗而不关闭流的句子可能很有价值。
因此,在编写库时,最好:
a) 总是记录
b) 记录任何不明显的东西
c) 从不记录(代码应该自己说话!)
我通常使用 b),我自己(因为代码可以是自记录的,否则)...