你遇到过的源代码中最好的注释是什么?
当前回答
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!!!!!!!!!"
他们还曾经问过我:“即使我们输入了错误的地址,我们如何才能找到正确的客户?”而这一切都是为了花生。
其他回答
注意上面代码中的bug;我只是证明了它是正确的,并没有尝试过。
这是唐纳德·克努斯写的。
//MailBody builders for two outgoing messages
StringBuilder hanz = new StringBuilder();
StringBuilder franz = new StringBuilder();
当我读到这篇文章时,我仍然会笑出声来……
// for 8 or 12 threads this does not affect much.
// Strange are the situations if not understood properly.
// Yoda strikes again
在多线程模块中!:)
这一点对其他人来说很有趣,但对我来说就不那么有趣了。我从一个开发人员那里继承了代码(ASP),而他自己也继承了它。第一个程序员编写了一些很难理解的代码。第二个开发者添加了如下评论(为了保护不那么无辜的人,名字被隐藏了):
'This code was written by **************.
'I haven't a clue what it does. He hasn't a clue what it does.
'Nobody else has a clue what it does or how it does it.
'It is something to do with data but **** knows what.
'The ******* still works so please do not change this code,
'even though it is a complete pile of ****.
那我为什么不觉得有趣呢?嗯,这是一个客户内部网的ASP代码。
...正是那位顾客向我强调了这条评论。
:-(
这是在PHP代码中找到的
$s=2; // chicken and bacon wrap for lunch
多么有用,幸运的是$s是不言自明的