@ 2013.07.22 , 17:30

Quora 精选:代码里的精彩注释

提问:计算机编程:有没有源代码里好玩的注释的例子

回答:Alex Regueiro,(1232票)

在 StackOverflow 上曾经有过一个同样问题的帖子,不过有个过份热心的管理员大姨妈删掉了那个帖子。

好在我非常幸运可以看到那些被删掉的答案,这里是我最喜欢的几个:

//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 42
//

// 亲爱的维护者:
//
// 如果你妄图在这里做点「优化」,
// 然后发现这简直就是坨屎
// 然后发现这个决定是个巨大的错误
// 请增加下面的变量,
// 这样可以提醒下一个维护者
//
// total_hours_wasted_here = 42
// (在这里浪费的时间共计 = 42 小时)

// When I wrote this, only God and I understood what I was doing
// Now, God only knows

// 当我写下这些东西的时候,只有上帝和我知道我写了啥
// 现在呢,只有上帝知道了
// 现在呢,上帝保佑我能看懂它们
// 感谢蛋友 @亿万潮湿 的指正

// sometimes I believe compiler ignores all my
comments

// 有时候我觉得编译器根本无视我的
注释

(小编: 梗在于这个「注释」的位置,这下编译器绝对不会无视了……)

// I dedicate all this code, all my work, to my wife, Darlene, who will
// have to support me and our three children and the dog once it gets
// released into the public.

// 这些代码都是我的心血,我的所有工作,献给我的妻子,达莲娜
// 她将一直支持我,包括我们的三个孩子,一条狗
// 直到这个软件发布为止
// 从软件发布以后

// drunk, fix later

// 喝多了,等会儿再修

// Magic. Do not touch.

// 神代码,别动。

(小编:其实是他也不知道这里为什么编译通过了,自己都不敢动)

#define TRUE FALSE
// Happy debugging suckers

# define TRUE FALSE
// 好好享受吧,混蛋

(小编:这是个变态,把「真」定义为「假」……)

long john; // silver

(小编:呵呵……冷,自己点

long long ago; /* in a galaxy far far away */

long long ago; /* 在很远很远的某个星系*/

(这么写,在 C99/C++0x 里可是编译不过的哟)

/**
* Always returns true.
*/
public boolean isAvailable() {
return false;
}

/**
* 返回值永远为真.
*/

public boolean isAvailable() {
return false;
}

// no comments for you
// it was hard to write
// so it should be hard to read

// 没注释给你看
// 因为程序很难懂
// 好不容易写出来的
// 所以注释也一定很难看懂的
// 你花点力气看也是应该的
// 感谢蛋友 @亿万潮湿 的指正

options.BatchSize = 300; //Madness? THIS IS SPARTA!

options.BatchSize = 300; //疯了? 这里可是斯巴达!

/**
* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you. Never gonna make you cry,
* never gonna say goodbye. Never gonna tell a lie and hurt you.
*/

/**
* 来到这里的勇敢的灵魂啊:你真是被选中之人,
* 勇敢的码农骑士啊,你不辞辛劳不眠不休,
* 来此拯救屎一般的代码。你是王的男人,真救星也
* 我说:我永不放弃你啊,永不打击你,
* 永不逃走把你甩啊,永不刨坑让你哭,
* 永不笑着说分离啊,永不扯淡把你骗。
*/

本文译自 Quora by Alex Regueiro,由 Junius 编辑发布。

支付宝打赏 [x]
您的大名: 打赏金额:
赞一个 (17)