你遇到过的源代码中最好的注释是什么?
当前回答
我尤其对此感到内疚,在我的大多数项目中嵌入了非建设性的注释、代码诗歌和小笑话(尽管我通常有足够的理智在发布代码之前删除任何直接冒犯的内容)。这里有一个我特别喜欢的,放置在一个设计很差的“上帝物体”下面:
/**
* 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
//
其他回答
//Visual Studio Bug Workaround:
//http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101677
//To fix 'CJumpToHelper::GetInstance()' : undeclared identifier compiler errors, change the number lines below
//until the file compiles correctly. (This needs to be done anytime a change is made to this file)
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
// (c) 2000 Applied Magic, Inc.
// Unauthorized use punishable by torture, mutilation, and vivisection.
啊,我一直很喜欢这个……
//uncomment the following line if the program manager changes her mind again this week
/*
FIXME: why the fuck did anyone ever think this kind of expensive iteration
was a good idea?
I don't have the code to share, but imagine this scenario. About a month or two after our Linux Sys Admin left for greener pastures, I had the pleasure of opening a shell script he'd written. I can't recall why I needed to edit it, but that's not what matters. What's important is that the script was about 40 lines long. I scrolled past the commenting (of which there were 37 lines) to reach the actual working code (3 lines). The code was great, but I was curious - why 37 lines of commenting? So, I scrolled to the top and proceeded to read. To my surprise, the commenting was a rap about what the three lines of code did and how to change it. The best part - it was a partial rip off of Nothing But A G Thing by Dr. Dre and Snoop D O DOUBLE G. Thanks Brian!