你遇到过的源代码中最好的注释是什么?
当前回答
我经历了一个睡眠不足的编程过程,开始只写引用自《搏击俱乐部》的评论。
多年后,我仍然在浏览代码,发现了一条让我发笑的评论。大多数只是随机的想法。然而,我确实保持我的评论行比率相当好!
// This shouldn't happen. The only way this can happen is if the
// <code>JFileChooser</code> has returned a <code>File</code> that doesn't exist
// on the system. If this happens we can't recover, and there is more than likely
// a rip in the space time continuum that the user is too distracted by to notice
// anything else.
/**
* This method leverages collective synergy to drive "outside of the box"
* thinking and formulate key objectives into a win-win game plan with a
* quality-driven approach that focuses on empowering key players to drive-up
* their core competencies and increase expectations with an all-around
* initiative to drive down the bottom-line. I really wanted to work the word
* "mandrolic" in there, but that word always makes me want to punch myself in
* the face.
*/
private void updateFileCountLabel() {
其他回答
我经常看到这种情况:
// TODO make this work
从《雷神之锤III》的资料中,我在一些随机的帖子中偶然发现了这一点。该文件的完整源代码可以在这里找到。这是一种非常快速的求平方根倒数的方法。至于最好的评论呢?当然,这是一种常见的方法,但考虑到它附着在直线上,它的神奇之处在于它的伟大之处。
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;
x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
#ifndef Q3_VM
#ifdef __linux__
assert( !isnan(y) ); // bk010122 - FPE?
#endif
#endif
return y;
}
} catch (PartInitException pie) {
// Mmm... pie
这是我曾经必须支持的实际代码。在努力理解AstaSaysGooGoo和AstaSaysGaaGaa(在那里有更多的astaTempVars被声明和使用)的逻辑之后,我准备放弃。我终于抬头看到了“@author”的评论,整件事开始有意义了。
/*
* @author Andrew Asta
*/
public class AstaClass{
private String astaVar1;
private String astaVar2;
private String astaVar3;
private String astaVar4;
private String astaVar5;
private String astaVar6;
private String astaVar7;
private String astaVar8;
private String astaVar9;
private String astaVar10;
public void AstaSaysGetData(){
//JDBC statement to populate astavars 1 through 10
//...
String astaSqlStatment = "Select astaCol1, astaCol2, astaCol3... From AstaTable Where...";
//..
//...
}
//Perform data manipulation on astavars...
public void AstaSaysGaaGaa(){
[removed for sake of brevity]
}
//Perform more data manipulation on astavars...
public void AstaSaysGooGoO(){
[removed for sake of brevity]
}
public void AstaSaysPersist(){
//JDBC statement to save astavars to DB
String astaSqlStatment = "Update AstaTable set astaCol1 = @astaVar1
, set astaCol2 = @astaVar2
, set astaCol3 = astaCol3...
Where...";
}
}
另外,我更改了实际作者的真实姓名,以避免我陷入任何纠纷等等…
// WARNING!!!
// Very perversive code ahead!
... about a 20 lines of "very perversive" code ...
// Now you can call your grandmother back. ;)