我们都知道,对我们的代码进行评论是编码风格的一个重要部分,使我们的代码可以理解为下一个人,或者甚至是我们在6个月左右的时间。
然而,有时评论不会削减芥末。 我不是在谈论明显的笑话或通风挫折,我说的是那些似乎试图解释的评论,但这样做很差,他们可能不会在那里。 评论太短,太神秘,或者只是完全错误。
作为一个故事,你能否分享一些你曾经看过的那些真的那么糟糕的东西,如果不是很明显的话,请展示它所指的代码并指出它有什么问题?
发布于 2018-12-08 14:18:11
未填充的javadoc样板评论特别无用。他们消耗了大量的屏幕空间而没有贡献任何有用的东西。最糟糕的是,出现一个这样的评论,其他数百个肯定会潜伏。
/**
* Method declaration
*
*
* @param table
* @param row
*
* @throws SQLException
*/
void addTransactionDelete(Table table, Object row[]) throws SQLException {
发布于 2018-12-08 15:25:25
像这样:
// This method takes two integer values and adds them together via the built-in
// .NET functionality. It would be possible to code the arithmetic function
// by hand, but since .NET provides it, that would be a waste of time
private int Add(int i, int j) // i is the first value, j is the second value
{
// add the numbers together using the .NET "+" operator
int z = i + j;
// return the value to the calling function
// return z;
// this code was updated to simplify the return statement, eliminating the need
// for a separate variable.
// this statement performs the add functionality using the + operator on the two
// parameter values, and then returns the result to the calling function
return i + j;
}
https://stackoverflow.com/questions/-100000921
复制相似问题