你遇到过的源代码中最好的注释是什么?
当前回答
不是真的评论:
DvLog::Log("This silly log message fixes a PSCRIPT5.DLL gpf when printing to Adobe.");
可悲的是,没有评论,PSCRIPT5.DLL真的炸了…
其他回答
// Any maintenance developer who can't quote entire Monty Python
// movies from memory has no business being a developer.
const string LancelotsFavoriteColor = "$0204FB"
Re eating one's own dogfood: We have the same term in our workplace (granted, only because I introduced it). My code is peppered with comments that say "TODO" and indicate something that ought to be done eventually, but a comment saying "DOGFOOD" (both keywords are always at the beginning of the comment, in all caps) means something that must be done before this program can be used even internally. It's a handy thing to search for, as the word "dogfood" is never going to appear in a quoted string - if it does, I can always just say "dog-food" or something - so even a case-insensitive search will come up with the right results.
Regarding zeroing the accumulator: I've done exactly the same thing when programming an Intel 80x86 (I started on the 8086 and moved up from there into the modern Pentiums). XORing a register with itself is the quickest and tightest way to clear it. Using "MOV AX,0" requires three bytes (opcode and two bytes of literal 16-bit zero), whereas "XOR AX,AX" is only two; it's even more noticeable with the 386-and-higher extended registers, where "MOV EAX,0" requires five bytes (four bytes of 32-bit zero). My C/C++ compiler always zeroes registers this way, so I'd assume it's still the best way (although I haven't studied opcode timing tables in ages, and probably both XOR reg,reg and MOV reg,imm take one clock).
有一次我发现:
// I wish (boss name) could do this by him self.
一段时间前我在一个PHP CMS中添加的注释。
if (/*you*/ $_GET['action']) { //celebrate
在20世纪80年代早期的某个时候,我们在PL/I中为公用事业编写财务建模代码。接到一个客户的电话,说代码在评论之后就爆炸了
/* Honest this works */
这家伙用了我们的标准金融方程花了大约15页的代数把一堆代码组合成一个方程。在三里岛事件后,当公用事业公司不得不以巨大的代价注销他们的核电站时,这个方程失败了,因为FIXED BIN 15(整数)溢出,如果代数没有发生,就不会发生这种溢出。