你遇到过的源代码中最好的注释是什么?


当前回答

这是显而易见的?

/** Logger */
private Logger logger = Logger.getLogger();

其他回答

// This part is more difficult

在方法的顶部。

大概有5行。

并不难。

这是唯一的评论。

在整个应用程序中。

这是我曾经必须支持的实际代码。在努力理解AstaSaysGooGoo和AstaSaysGaaGaa(在那里有更多的astaTempVars被声明和使用)的逻辑之后,我准备放弃。我终于抬头看到了“@author”的评论,整件事开始有意义了。

/*

* @author Andrew Asta
*/
public class AstaClass{

    private String astaVar1;    
    private String astaVar2;    
    private String astaVar3;    
    private String astaVar4;    
    private String astaVar5;    
    private String astaVar6;    
    private String astaVar7;    
    private String astaVar8;    
    private String astaVar9;    
    private String astaVar10;   

    public void AstaSaysGetData(){
        //JDBC statement to populate astavars 1 through 10
        //...
        String astaSqlStatment = "Select astaCol1, astaCol2, astaCol3... From AstaTable Where...";
        //..
        //...
    }

    //Perform data manipulation on astavars...
    public void AstaSaysGaaGaa(){
          [removed for sake of brevity]
    }


    //Perform more data manipulation on astavars...
    public void AstaSaysGooGoO(){
        [removed for sake of brevity]
    }

    public void AstaSaysPersist(){      
        //JDBC statement to save astavars to DB 
        String astaSqlStatment = "Update AstaTable set astaCol1 = @astaVar1
                                                  , set astaCol2 = @astaVar2
                                                  , set astaCol3 = astaCol3... 
                                                  Where...";
    }
}

另外,我更改了实际作者的真实姓名,以避免我陷入任何纠纷等等…

// fix for groupid > 9 
// if groupid ever gets to 100 everything will break (again)

if (groupid < 10) {
groupid = "0" + groupid;
}

这是在PHP代码中找到的

$s=2; // chicken and bacon wrap for lunch

多么有用,幸运的是$s是不言自明的

不是代码注释,而是SVN在同一个文件上提交注释:

第一次提交(在测试人员返回结果后,再进行数十次提交):

Squashed some IPR mod bugs. The were big and juicy ones, too.

2日提交:

Squashed some more mod bugs. Those are some nasty bugs, them mod bugs...

3rd:

Squashed some more mod bugs. They are like cockroaches: they'll live through a nuclear war.

4th:

Squashed some more John bugs. They too are like cockroaches: they appear anywhere John goes. Wait. That doesn't sound right.

5:

Same John bug. It didn't die, just played 'possum.

是的,我厌倦了"修复bug"