你遇到过的源代码中最好的注释是什么?


当前回答

我不知道这是有趣还是悲伤..但是和我一起工作的一个实习生有这个小宝石来计算每个单位的价格

...

// get the units from the form 
int numUnits = Integer.parseInt(request.getParameter("num_pieces")); // this break at random times

//price 
float price = Float.parseFloat(request.getParameter("price")); // same as above

// Under certain conditions the following code blows up. I don't know those conditions.
float pricePerUnit = price / (float)numUnits;

...

其他回答

'Do not optimize these next two lines. Compiler bugs lurk.

他们做到了。将变量压缩到第二行表达式中会导致跳到堆中间并尝试执行数据。

/* Look not upon this file lest your eyes be burnt from your head. */

我能说什么呢?我当时是实习生,夏天快结束了。我们可以说,我对我的文件责任缺乏认真的承诺。

在几年前编写Perl时,我在顶部和底部添加了这些注释:

# <magic type="voodoo">

...

# </magic>

下一个研究它的人在Perl中并不是那么热门,他花了一段时间搜索文档,看看“魔法”和“巫毒”是怎么做的。从那以后,我试着添加更多有用的评论……

// I have to find a better job

这个我在Python 2.5的“twisted”包中找到的(文件是tcp.py在第371行)

# Limit length of buffer to try to send, because some OSes are too
# stupid to do so themselves (ahem windows)
return self.socket.send(buffer(data, 0, self.SEND_LIMIT))