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


当前回答

整个函数非常棒(来自Linux的sunhme.c驱动程序,用于被Sun戏称为“快乐套餐”的网卡)。因为在那之前的卡片是“巨无霸”。明白了吗?明白了吗?)

static void happy_meal_tcvr_write(struct happy_meal *hp,
                              void __iomem *tregs, int reg,
                              unsigned short value)
{
    int tries = TCVR_WRITE_TRIES;

    ASD(("happy_meal_tcvr_write: reg=0x%02x value=%04x\n", reg, value));

    /* Welcome to Sun Microsystems, can I take your order please? */
    if (!(hp->happy_flags & HFLAG_FENABLE)) {
            happy_meal_bb_write(hp, tregs, reg, value);
            return;
    }

    /* Would you like fries with that? */
    hme_write32(hp, tregs + TCVR_FRAME,
                (FRAME_WRITE | (hp->paddr << 23) |
                 ((reg & 0xff) << 18) | (value & 0xffff)));
    while (!(hme_read32(hp, tregs + TCVR_FRAME) & 0x10000) && --tries)
            udelay(20);

    /* Anything else? */
    if (!tries)
            printk(KERN_ERR "happy meal: Aieee, transceiver MIF write bolixed\n");

    /* Fifty-two cents is your change, have a nice day. */

}

其他回答

我看到一些旧的fortran代码:

     integer *4 one,two,three;

c    asssign one to 100 before entering the loop
     one=100;
catch (Ex as Exception)
{
     // oh crap, we should do something.
}

没有什么比一个空的catch块更能让人觉得代码是健壮的....

有一些旧的javascript代码,写得很好。然后是一条评论线

// and there is where the dragon lives

接下来是一个功能,4个人花了一天时间来理解它在做什么。最后我们意识到它根本没用,什么都没有。

// I know the line below is wrong, but it came that way from our IP vendor, and 
// the driver won't work if you "fix" it. I've had to revert this change 4 times
// now. Leave it alone, or I will hunt you down and hurt you
if (r = 0) {
    /* bunch of code here */
}
else
{
   /* even more code here */
}
[onload_1;block=begin;when 1=0]

Some of the techinques in this template are rather obscure, just trust me, they need to be there.
OTOH a better sollution would be to create a few seperate templates and pick one in the php-script...

[onload_1;block=end]