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


当前回答

// simply copied from another code

其他回答

在linux 1.0内核调度器(schedule .c)中:

Dijkstra可能讨厌我。

/*
 *  'schedule()' is the scheduler function. It's a very simple and nice
 * scheduler: it's not perfect, but certainly works for most things.
 * The one thing you might take a look at is the signal-handler code here.
 *
 *   NOTE!!  Task 0 is the 'idle' task, which gets called when no other
 * tasks can run. It can not be killed, and it cannot sleep. The 'state'
 * information in task[0] is never used.
 *
 * The "confuse_gcc" goto is used only to get better assembly code..
 * Dijkstra probably hates me.
 */
asmlinkage void schedule(void)

(…)

下面的代码是在Python模拟教程中看到的。

# This is my rifle.
def rifle(type='hunting'):
    print('This is my (%s) rifle.' % type)

# This is my gun.
def gun(type='hand'):
    print('This is my (%s) gun.' % type)

# This is for fighting.
def fighting(type='illegal'):
    print('This is for (%s) fighting.' % type)

# This is for fun.
def fun(type='gaming'):
    print('This is for (%s) fun.' % type)

作者一定是《恶搞之家》的粉丝。^ _ ^

我喜欢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.  */

这是一个旧的IOCCC获奖条目,我不得不下载整个获奖档案——一个巨大的1.4 M——和grep的几个短语,我记得错了才找到它。

从语法上看,这可能不是注释。或许是这样。我还没想明白。它肯定没有注释分隔符,但也没有字符串分隔符。

C="Lint says "argument Manual isn't used."  What's that
mean?";

没有价格来猜测棉绒的产量。

对于好奇的人来说,这个条目在这里。

aComment = 'this is not aComment' # this is aComment
class T(object):
    def f(this):
        this is not aComment