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


当前回答

早在80年代早期,我在汇编器中看到了这个(引用于模糊的记忆):

I don't understand how the following bit works, but it worked in the program I stole it from.

其他回答

//  Hey, your shoe's untied!

后面跟着一些可疑的代码,在这些代码中,

//  Keep looking!  I think it was the other shoe!

最后,

//  How strange -- I must be seeing things.  Anyhow, I'm going to go take a shower, now...

不是注释,而是属性

[ThereBeDragons]

还有一个是我在IHttpHandler的实现中看到的

//What is this?
public bool IsReusable
{
    get{return false;}
}

我看到有人对代码的评论:

// This comment is self explanatory.

我猜他是想说“可变的”,但这个错误造成了一个有趣的评论……想想这里的循环逻辑,以及写它的徒劳。

曾经有一个为我工作的程序员在他的代码中加入了“Style”注释,他在代码中编写了关于特定实现细节的内部争论,当他在某个特定的编码决策上被否决时,他就会离开。

例子:

的风格 '这是有争议的,但我传递图像句柄,而不是简单地 '传递缩放值,以保持调用代码更简单(通过a '一对声明语句)。或者,我可以传递这些数据 成员,但这将违反封装。

的风格 就像我在其他地方做过的一样,我将正式提出抗议 的表格),将注释序列化的实现视为 '一个属性,而不是一对Load/Save方法。这可能是 “风格的问题,值得商榷。

我喜欢GNU双utils中的一些注释。这个来自BFD som.c:

/* You'll never believe all this is necessary to handle relocations
   for function calls.  Having to compute and pack the argument
   relocation bits is the real nightmare.

   If you're interested in how this works, just forget it.  You really
   do not want to know about this braindamage.  */

这个也是:

/* Don't ask about these magic sequences.  I took them straight
   from gas-1.36 which took them from the a.out man page.  */

...

/* Keep track of exactly where we are within a particular
   space.  This is necessary as the braindamaged HPUX
   loader will create holes between subspaces *and*
   subspace alignments are *NOT* preserved.  What a crock.  */

另一个:

/* We will NOT put a fucking timestamp in the header here. Every
   time you put it back, I will come in and take it out again. ... */

从气体:

/* Yes this is ugly (storing the broken_word pointer
   in the symbol slot).  Still, this whole chunk of
   code is ugly, and I don't feel like doing anything
   about it.  Think of it as stubbornness in action.  */