你遇到过的源代码中最好的注释是什么?
当前回答
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).
其他回答
在JUnit API中找到:
/**
* ...as the moon sets over the early morning Merlin, Oregon
* mountains, our intrepid adventurers type...
*/
public Test createTest(Class theClass, String name) {
...
}
我一直很喜欢Paul DiLascia在他的文件头中写的:
// If this code works, it was written by Paul DiLascia. If not, I don't know
// who wrote it
// For the sins I am about to commit, may James Gosling forgive me
来自Linux内核源代码:
linux /包括/ asm-i386 / hw_irq。h:
/*
* subtle. orig_eax is used by the signal code to distinct between
* system calls and interrupted 'random user-space'. Thus we have
* to put a negative value into orig_eax here. (the problem is that
* both system calls and IRQs want to have small integer numbers in
* orig_eax, and the syscall code has won the optimization conflict ;)
*
* Subtle as a pigs ear. VY
*/
int main(void)
/* Program starts here */