你遇到过的源代码中最好的注释是什么?
当前回答
来自Java 1.2的SwingUtilities:
doRun.run(); // ... "a doo run run".
其他回答
I was doing a database in Access, very simple thing - at least it was supposed to be at the start or I would have done it in Delphi. The client wanted to be able to get the customer info out of the database but they would not enter enough information to reliably identify the customer. I told them to use the phone number as the key as each customer (the way they worked, not for everyone) would have a different number. After a few frantic calls from them, (It's not working we can't enter the customer) I discovered that they were too lazy to look up the phone numbers from their old system and were trying to enter all the numbers they did not know as "n/a". In trying to sort this out for them I ended up with a lot of checking loops in the code and had the comment beside one outcome "This should never be reached if they do what they are supposed to do!!!!!!!!!"
他们还曾经问过我:“即使我们输入了错误的地址,我们如何才能找到正确的客户?”而这一切都是为了花生。
下面是我在不同时间放入代码中的一些代码。有些不是严格意义上的评论,但它们是相同的概念。
在一个跨平台项目中,只需要在一个平台上执行一些特殊代码:
//If defined, will include all the Windows-specific code.
#define LOSE
#ifdef LOSE
#include <windows.h> //WIN32. Duh.
#endif
---------------------------------------------------
//Stolen from other_project_name.cpp
---------------------------------------------------
/*
* These comments have been lifted from propagate() and, though they no longer apply to the code, they may still be of value somewhere. Original tabbing and structural elements have been preserved.
*/
//CAUTION: This has a major Bobby Tables risk. Even if a rulebuilder is used, there's still the risk of something getting corrupted in the database itself.
//Reading text from anywhere and simply slotting it into an SQL statement is a major security risk. (With thanks to xkcd for the name "Bobby Tables".)
//Requirement: Eliminate one Bobby Tables by changing [redacted] to be not just straight SQL.
[lots more comments that are not as funny]
/*
* End of lifted comments. There should not be any executable code between these markers.
*/
---------------------------------------------------
/*
Okay. It's unrecognized. Why is this a fatal error? It's actually very closely akin to the miswart of botched #includes being a fatal. When writing a C/C++
program, you need your headers, and if you don't have one, chances are there'll be a million cascaded errors; so by making "unable to open asdf.h" a fatal,
the compiler suppresses all those errors about undefined symbols and potentially misspelled type names.
*/
---------------------------------------------------
//If someone tries to import 'id' as a field name, it won't work. (We already have our own id.) But I think the probability is so low that I can afford to be funny.
if (!stricmp(ptr,"id")) {warn(0,"Import","","'id' is a reserved word and cannot be used as a column name. (Try 'ego' or 'superego'.)"); return;}
---------------------------------------------------
//Need a place to squirrel away SQL statements somewhere
char *uts[1024]; //Unified Temporary Storage. (Why? Because I said so.)
int nuts=0; //What is it that squirrels keep? Ha!
int utsid[sizeof uts/sizeof *uts];
---------------------------------------------------
/**************************************\
* NOTE: This sets tilde.action. If a *
* tilde header does not exist in the *
* import file (not the _content_, if *
* the entire column isn't there), it *
* will duplicate down through all of *
* the rows. This is fine for ~id, as *
* that will never be changed; and if *
* ~Quantity is blank, that throws an *
* error in 'Add'. With ~Action, I am *
* not so certain. I THINK it'd be OK *
* to dup-down most of the time... if *
* the user only ever imports Adds or *
* Revises, but never both at once in *
* a single import. So for safety, to *
* allow a blank ~Action to revise OR *
* add, I'm breaking the check out to *
* a new variable - the curaction. In *
* most cases, it won't be needed, so *
* it's a waste; but it isn't like it *
* has to copy the entire tilde.*, so *
* it's only a small waste. So it can *
* waste a register... big deal. OK ! *
\**************************************/
---------------------------------------------------
//if (!response) // we're going to crash
//if (!items) // we're going to crash
//TODO: Don't crash
---------------------------------------------------
我的很多评论都隐晦地提到了电影或音乐剧,但如果你不了解这部剧,它们就不会那么有趣了。
// haack, phil haack
and:
/* hack, hack, hack, hack, hack hack, hack, hack
* hackity hack, oh wonderful hacks
* wonderful hacks, oh wonderful hack, hack, hack
* hack hack hack... and spam
*/
编辑:刚刚在我的一些代码中发现了这个(项目希望保持匿名):
// yikes, we need to:
/*
* o
* -|- < US CROSSING PLATFORM
* |\
************************************************
* | ^ PLATFORM |
* | T |
* | TROLL^ |
*/
// right now:
/*
* o ./_ |
* -|-[]\ | (_'_) () (\) | ) \|/ (S) < WALL
* |\ | ^ FRIENDLY MESSAGE FROM YOUR FRIENDS AT MICROSOFT
* ***********************************************
* | ^PLATFORM |
* ^ SPRAY CAN (IN HAND)
*/
public static class DefaultFonts
{
public static string SansSerifPath
{
get { return @"C:\Windows\Fonts\arial.ttf"; }
}
public static string SerifPath
{
get { return @"C:\Windows\Fonts\times.ttf"; }
}
public static string MonospacePath
{
get { return @"C:\Windows\Fonts\courier.ttf"; }
}
}
我好喜欢双关语。
public int hashCode() {
//sucks, but what're you gonna do
/*
int hash = 7;
for (int i = 0; i < array.length; i++)
hash = hash * 31 * (null == array[i] ? 0 : array[i].hashCode());
return hash;
*/
return 0;
}
#ifdef TRACE
#undef TRACE /* All your trace are belong to us. */
#endif
#define TRACE ....