你見過哪些奇趣的代碼注釋?

RT


Stack Overflow 上有個關於你見過的最好(gao)的注釋的帖子:What is the best comment in source code you have ever encountered?

摘錄其中一部分貼出來:

腦洞大開

/**
* 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.
*/

歷史的教訓

//
// 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
//

忠告

/*
* You may think you know what the following code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many a sleepless
* night cursing the moment you thought youd be clever
* enough to "optimize" the code below.
* Now close this file and go play with something else.
*/

「哈哈」太賤了

Exception up = new Exception("Something is really wrong.");
throw up; //ha ha

這條我忍不住笑了

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

這條適合處女座

// Autogenerated, do not edit. All changes will be undone.

笑點低系列

// 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.

吐槽

// somedev1 - 6/7/02 Adding temporary tracking of Login screen
// somedev2 - 5/22/07 Temporary my ass

喝醉了也要寫注釋也是蠻敬業的

// drunk, fix later

犯賤系列

#define TRUE FALSE
//Happy debugging suckers

Catch (Exception e) {
//who cares?
}

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

迷之自信

try {

} finally { // should never happen

}

跟著唱吧

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

其它

//This code sucks, you know it and I know it.
//Move on and call me an idiot later.


以下為真實事例:
幾年前我寫了一段程序,有一段邏輯頗有點複雜。我就寫了個注釋:
# See also &<一個公司內部文檔的鏈接&>
之後我再也沒動過這段代碼。幾年過去了,一個偶然的機會我再次需要維護這段代碼,然後發現注釋變成了這個樣子:
# See also &<一個公司內部文檔的鏈接&>
# smay 2011.12.5 the link above is no longer valid. New link is here: &<....&>
# smay 2012.5.9 anyway, I don"t think the doc tells you how the code works.
# kgupta 2012.8.21 yes u r right. the doc was totally bogus.
# &<我司的VP&> 2013.6.11 since the doc is bogus, I re-wrote the code to match the reality.
# &<我司的VP&> 2013.6.15 no i was wrong. and you are all wrong. the doc was so correct and so does the code. whoever wrote the code in the first place was a genius!
# &<我司的VP&> can someone tell me how I can get the old revision back? my version doesn"t quite work and i don"t know why ...

頓時明白了為什麼我又被叫回來維護這段代碼……



# 不要再用 anal 做變數名了
# 你們想用 anal 這個縮寫來表示analyze(分析),可是 anal 這個單詞的意思是「肛門」
# 我特么在哪都能看到 anal 這個詞!
# 請不要再這麼做了!
# 你們要用就用analyze,或者xbvvzr,要不然用什麼其他的都可以。就是別寫成 anal_insert 或者 anal_check了
# insert是插入的意思,check是檢查的意思,自行腦補吧


http://wpkg.org在Javascript中給的防止DNS污染忠告:

// If you didn"t retrieve this file on purpose, it means your DNS is poisoned!
// If you"re connecting from China, please use OpenDNS or Google public DNS servers (and verify the queries are not intercepted on the way)!
// Even if you"re connecting using VPN, your DNS queries may be sent to local (poisoned) DNS server!
// If you"re not connecting from China, it means your device is probably infected with malicious software! (補充:看起來這個防火牆全世界都很出名)
// See http://wpkg.org/Notice_for_users_affected_by_the_Great_Firewall_of_China for more info

如果打開這個文件有這樣的注釋,代表你應該按照他說的這樣做了http://connect.facebook.net/en_US/sdk.js


最早的一個代碼里
密鑰更新那塊寫著
(大意)這密鑰有效期十年,這代碼肯定不會用那麼久。

然而公司現在十幾年了
在第十年的時候發現這個問題,但是這段歷史代碼已經沒幾個人能看懂了(對 perl寫的)

後來好像是又把他請出山了…………

我們內部每次都拿這個梗開玩笑


記得微信出過一個桌面測試版,某一天居然可以在chrome上打開公眾號oauth2.0跳轉頁面(也就是含有微信openid等session信息頁面),居然可以看見微信XX功能的前端代碼,看到有一行注釋讓我笑了:

當時截圖發朋友圈了,第二天再也打不開跳轉頁了,提示:請使用微信客戶端打開。哈哈,這個必須匿了。。。。不然就暴露了。。。。
————————————————————————————————————————
忘了加上一段通用代碼

---------------------------------------好吧,給出文字版----------------------------------------------------

// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O = /O
// ____/`---"\____
// . " \| |// `.
// / \||| : |||//
// / _||||| -:- |||||-
// | | \ - /// | |
// | \_| ""---/"" | |
// .-\__ `-` ___/-. /
// ___`. ." /--.-- `. . __
// ."" "&< `.___\_&<|&>_/___." &>""".
// | | : `- `.;` _ /`;.`/ - ` : | |
// `-. \_ __ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-"======
// `=---="
//
// .............................................
// 佛祖保佑 永無BUG
// 佛曰:
// 寫字樓里寫字間,寫字間里程序員;
// 程序人員寫程序,又拿程序換酒錢。
// 酒醒只在網上坐,酒醉還來網下眠;
// 酒醉酒醒日復日,網上網下年復年。
// 但願老死電腦間,不願鞠躬老闆前;
// 賓士寶馬貴者趣,公交自行程序員。
// 別人笑我忒瘋癲,我笑自己命太賤;
// 不見滿街漂亮妹,哪個歸得程序員?


來源:蝦米 mac 客戶端發現個好玩的注釋 - V2EX

具體的圍觀步驟如下

1.現在去蝦米官網下載 Mac 客戶端。

2.右擊「蝦米音樂.app 」,選中「顯示包內容」。

3.在"/Contents/Resources/"中找到"app.asar",並複製到桌面

4.用終端全局安裝 npm 的 asar 包,"npm install asar -g"

5.用終端 cd 到桌面,並解密 asar,並生成 tmp 文件夾。"cd ~/Desktop asar e app.asar tmp"

6.把 tmp 文件夾拖拽到 Atom,用「 shift+command+F 」喚出全局搜索

7.搜索「窮逼」

用文本編輯器查看桌面客戶端文件夾下的 app.asar 文件就看到了

http://telegra.ph/%E8%99%BE%E7%B1%B3%E6%A1%8C%E9%9D%A2%E5%AE%A2%E6%88%B7%E7%AB%AF-appasar%E5%88%A4%E6%96%ADvip%E4%BB%A3%E7%A0%81-11-19


有比這更奇葩的注釋嗎?
好人一生平安


完善別人代碼時候看到這個,心裡一萬匹草泥馬呼嘯而過。


來自 stdio.h

某次在zhihu上看到的,感覺特別有意思~也有可能是我的笑點有點低。=w=

還有一隻具有魔性的doge.

來自某ACG網站。--------------------------------------------------------文字版來了-----------------------------------------------------------

/* Standard streams. */
extern struct _IO_FILE *stdin; /* Standard input stream. */
extern struct _IO_FILE *stdout; /* Standard output stream. */
extern struct _IO_FILE *stderr; /* Standard error output stream. */
/* C89/C99 say they"re macros. Make them happy. */
#define stdin stdin
#define stdout stdout
#define stderr stderr

&
&