你在源代码中遇到过的最好的注释是什么?
518 回答
我对此感到特别内疚,在我的大多数项目中嵌入了非建设性的评论、代码诗和小笑话(尽管我通常有足够的意识在发布代码之前删除任何直接冒犯的东西)。这是我特别喜欢的一个,放置在一个设计不佳的“上帝之物”的很远很远的地方:
/**
* For the brave souls who get this far: You are the chosen ones,
* the valiant knights of programming who toil away, without rest,
* fixing our most awful code. To you, true saviors, kings of men,
* I say this: never gonna give you up, never gonna let you down,
* never gonna run around and desert you. Never gonna make you cry,
* never gonna say goodbye. Never gonna tell a lie and hurt you.
*/
抱歉!!!!我简直无法自拔……!
还有一个,我承认我并没有真正释放到野外,尽管我很想在我不太直观的课程中这样做:
//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 42
//
Exception up = new Exception("Something is really wrong.");
throw up; //ha ha
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
stop(); // Hammertime!
这似乎阻止了白痴弄乱我的代码......
// Autogenerated, do not edit. All changes will be undone.
// sometimes I believe compiler ignores all my comments
// I dedicate all this code, all my work, to my wife, Darlene, who will
// have to support me and our three children and the dog once it gets
// released into the public.
//Code sanitized to protect the foolish. using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.Web.UI; namespace Mobile.Web.Control { /// <summary> /// Class used to work around Richard being a fucking idiot /// </summary> /// <remarks> /// The point of this is to work around his poor design so that paging will /// work on a mobile control. The main problem is the BindCompany() method, /// which he hoped would be able to do everything. I hope he dies. /// </remarks> public abstract class RichardIsAFuckingIdiotControl : MobileBaseControl, ICompanyProfileControl { protected abstract Pager Pager { get; } public void BindCompany(int companyId) { } public RichardIsAFuckingIdiotControl() { MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity(); } private void MakeSureNobodyAccidentallyGetsBittenByRichardsStupidity() { // Make sure nobody is actually using that fucking bindcompany method MethodInfo m = this.GetType().GetMethod("BindCompany", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (m != null) { throw new RichardIsAFuckingIdiotException("No!! Don't use the fucking BindCompany method!!!"); } // P.S. this method is a joke ... the rest of the class is fucking serious } /// <summary> /// This returns true if this control is supposed to be doing anything /// at all for this request. Richard thought it was a good idea to load /// the entire website during every request and have things turn themselves /// off. He also thought bandanas and aviator sunglasses were "fuckin' /// gnarly, dude." /// </summary> protected bool IsThisTheRightPageImNotSureBecauseRichardIsDumb() { return Request.QueryString["Section"] == this.MenuItemKey; } protected override void OnLoad(EventArgs e) { if (IsThisTheRightPageImNotSureBecauseRichardIsDumb()) { Page.LoadComplete += new EventHandler(Page_LoadComplete); Pager.RowCount = GetRowCountBecauseRichardIsDumb(); } base.OnLoad(e); } protected abstract int GetRowCountBecauseRichardIsDumb(); protected abstract void BindDataBecauseRichardIsDumb(); void Page_LoadComplete(object sender, EventArgs e) { BindDataBecauseRichardIsDumb(); } // the rest of his reduh-ndant interface members public abstract string MenuItemName { get; set; } public abstract string MenuItemKey { get; set; } public abstract bool IsCapable(CapabilityCheck checker, int companyId); public abstract bool ShowInMenu { get; } public virtual Control CreateHeaderControl() { return null; } } }
更新: 代码的原作者已经出局了,所以我必须在应得的地方给予赞扬。Dan McKinley在我刚开始工作后不久就离开了我所在的公司,他更多地谈论了代码,解释了一些背景和一些“Richard”写的“WTF”。
// somedev1 - 6/7/02 Adding temporary tracking of Login screen
// somedev2 - 5/22/07 Temporary my ass
// drunk, fix later
真希望我在开玩笑。并且了解编写代码的开发人员,我认为他是字面意思。
// Magic. Do not touch.
#define TRUE FALSE
//Happy debugging suckers
// I'm sorry.
return 1; # returns 1
/* This is O(scary), but seems quick enough in practice. */
后跟四个嵌套的 for 循环
// Replaces with spaces the braces in cases where braces in places cause stasis
$str = str_replace(array("\{","\}")," ",$str);
它充分说明了我们的职业,当被问及“最佳评论”时,我们都回答了我们能找到的最糟糕的评论......
long john; // silver
Catch (Exception e) {
//who cares?
}
/**
* Always returns true.
*/
public boolean isAvailable() {
return false;
}
永远不要依赖评论...
/*
* You may think you know what the following code does.
* But you dont. Trust me.
* Fiddle with it, and youll spend many a sleepless
* night cursing the moment you thought youd be clever
* enough to "optimize" the code below.
* Now close this file and go play with something else.
*/
try {
} finally { // should never happen
}
来自:https ://github.com/zepouet/Xee-xCode-4.5/blob/master/XeePhotoshopLoader.m#L108
// At this point, I'd like to take a moment to speak to you about the Adobe PSD
// format. PSD is not a good format. PSD is not even a bad format. Calling it
// such would be an insult to other bad formats, such as PCX or JPEG. No, PSD
// is an abysmal format. Having worked on this code for several weeks now, my
// hate for PSD has grown to a raging fire that burns with the fierce passion
// of a million suns.
//
// If there are two different ways of doing something, PSD will do both, in
// different places. It will then make up three more ways no sane human would
// think of, and do those too. PSD makes inconsistency an art form. Why, for
// instance, did it suddenly decide that *these* particular chunks should be
// aligned to four bytes, and that this alignement should *not* be included in
// the size? Other chunks in other places are either unaligned, or aligned with
// the alignment included in the size. Here, though, it is not included. Either
// one of these three behaviours would be fine. A sane format would pick one.
// PSD, of course, uses all three, and more.
//
// Trying to get data out of a PSD file is like trying to find something in the
// attic of your eccentric old uncle who died in a freak freshwater shark
// attack on his 58th birthday. That last detail may not be important for the
// purposes of the simile, but at this point I am spending a lot of time
// imagining amusing fates for the people responsible for this Rube Goldberg of
// a file format.
//
// Earlier, I tried to get a hold of the latest specs for the PSD file format.
// To do this, I had to apply to them for permission to apply to them to have
// them consider sending me this sacred tome. This would have involved faxing
// them a copy of some document or other, probably signed in blood. I can only
// imagine that they make this process so difficult because they are intensely
// ashamed of having created this abomination. I was naturally not gullible
// enough to go through with this procedure, but if I had done so, I would have
// printed out every single page of the spec, and set them all on fire. Were it
// within my power, I would gather every single copy of those specs, and launch
// them on a spaceship directly into the sun.
//
// PSD is not my favourite file format.
const int TEN=10; // As if the value of 10 will fluctuate...
#Christmas tree initializer
toConnect = []
toRead = [ ]
toWrite = [ ]
primes = [ ]
responses = {}
remaining = {}
大约30页xslt的中间
<!-- Here be dragons -->
long long ago; /* in a galaxy far far away */
在完全未注释的 2000 行方法中
{
{
while (.. ){
if (..){
}
for (.. ){
}
.... (just putting in the control flow here, imagine another few hundred ifs)
if(..) {
if(..) {
if(..) {
...
(another few hundred brackets)
}
}
} //endif
(实际上,有一天我把所有的括号都找出来了,只是为了看看它有多糟糕,而且,没有格式化,得到了这个:
{{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{} {{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}
endif 出现在第 800 行左右)
//This code sucks, you know it and I know it.
//Move on and call me an idiot later.
// If this comment is removed the program will blow up
double penetration; // ouch
/////////////////////////////////////// this is a well commented line
// I don't know why I need this, but it stops the people being upside-down
x = -x;
其中最经典的一条是皮埃尔·德·费马 (Pierre de Fermat) 对他著名的“最后定理”的评论:“这一页的页边距太小,无法写下证明”。
350 多年后才找到证据……
(根据维基百科,这是原文:)
Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et generaliter nullam infinitum ultra quadratum potestatem in duos eiusdem nominis fas est dividere cuius rei demoem mirabilem sane detexi。Hanc marginis exiguitas non caperet。
...并翻译成英文:
(不可能将一个立方体分成两个立方体,或者将一个四次方分成两个四次方,或者一般来说,任何高于第二个的幂都分成两个类似的幂。我发现了一个真正奇妙的证明,这个边距是太窄而无法容纳。)
// I am not sure if we need this, but too scared to delete.
从 Java 1.2 SwingUtilities:
doRun.run(); // ... "a doo run run".
# To understand recursion, see the bottom of this file
在文件的底部:
# To understand recursion, see the top of this file
This one was a living proof, in production code, of micro-management effects in our team:
// I am not responsible of this code.
// They made me write it, against my will.
... followed by less than optimal code, conceived by our beloved technical director, who was quite fond of forcing down both code and coding guidelines into developers' throats (*).
Of course, when the project leader searched for the cause of a bug, and found it was inside the "less than optimal code", he was less than amused...
(*) I am, of course, mentioning the Mighty VB King... If you want to assess the full magnitude of the power of the Mighty VB King, you can read the following SO post: What was the strangest coding standard rule that you were forced to follow? ...
我经历了一次睡眠不足的编码运行,开始只写引用搏击俱乐部的评论。
多年后我仍在翻阅代码,发现一条让我发笑的评论。他们中的大多数只是随机的想法。然而,我确实保持我的评论与线条的比例相当不错!
// 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() {
许多年前(大约 1994 年)我正在为您可能听说过的一家大型跨国软件公司开发 Oracle PRO*C 应用程序。我正在开发的应用程序是一个庞大的 Oracle 应用程序,他们有一个实用程序可以在一夜之间运行整理数据并进行各种聚合计算。每次需要将任何事情作为批处理作业执行时,它都会被塞进这个实用程序中,你可以想象它变成了一个绝对的怪物。值得注意的是,它对如此庞大的程序的评论数量很少。
它确实拥有的少数评论之一仍然是我见过的关于纯 WTF'ness 的最好评论......我试图在一个有数百行长的函数中找到一个错误,并且就在它的中间是唯一的函数中的注释:
/* I did this the other way */
直到今天,这仍然是我见过的最好的评论。
/* Please work */
//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.
我今天才发现这个:
//private instance variable for storing age
public static int age;
/* You are not meant to understand this */
//I am not sure why this works but it fixes the problem.
这是在一组代码在技术上确实解决了它本应解决的问题但破坏了其他 3 件事之前......
// no comments for you
// it was hard to write
// so it should be hard to read
/* Halley's comment */
options.BatchSize = 300; //Madness? THIS IS SPARTA!
我们的 DBA 在第三方编写的 3000 行存储过程中发现了这一点。
/* IF DOLPHINS ARE SO SMART, HOW COME THEY LIVE IN IGLOOS? */
// I have to find a better job
关于js代码:
// hack for ie browser (assuming that ie is a browser)
/* Emits a 7-Hz tone for 10 seconds.
True story: 7 Hz is the resonant frequency of a
chicken's skull cavity. This was determined
empirically in Australia, where a new factory
generating 7-Hz tones was located too close to a
chicken ranch: When the factory started up, all the
chickens died.
Your PC may not be able to emit a 7-Hz tone. */
main()
{
sound(7);
delay(10000);
nosound();
}
(the sound function in the Turbo C version 2.0 Reference Guide)
... 要么死 // 婊子
试着在谷歌代码搜索中输入你最喜欢的脏话,它会消磨很多沉闷的小时。我最喜欢的一些例子:
/* These magic numbers are fucking stupid. */
/* Dear free software world, do you NOW see we are fucking
things up?! This is insane! */
/* We will NOT put a fucking timestamp in the header here. Every
time you put it back, I will come in and take it out again. */
# However, this only works if there are MULTIPLE checkboxes!
# The fucking JS DOM *changes* based on one or multiple boxes!?!?!
# Damn damn damn I hate the JavaScript DOM so damn much!!!!!!
/* TODO: this is obviously not right ... this whole fucking module
sucks anyway */
/* FIXME: please god, when will the hurting stop? Thus function is so
fucking broken it's not even funny. */
和我个人的最爱
# code below replaces code above - any problems?
# yeah, it doesn't fucking work.
关于链表的初始化:
last = first; /* Biblical reference */
简洁又搞笑。
有人抱怨说,“最好的”评论提出了最差的评论。恕我直言,它们更有趣,所以“更好”,但这是我读过的最诚实的评论:
/*
Major subtleties ahead: Most hash schemes depend on having a "good" hash
function, in the sense of simulating randomness. Python doesn't: its most
important hash functions (for strings and ints) are very regular in common
cases:
>>> map(hash, (0, 1, 2, 3))
[0, 1, 2, 3]
>>> map(hash, ("namea", "nameb", "namec", "named"))
[-1658398457, -1658398460, -1658398459, -1658398462]
>>>
This isn't necessarily bad! To the contrary, in a table of size 2**i, taking
the low-order i bits as the initial table index is extremely fast, and there
are no collisions at all for dicts indexed by a contiguous range of ints.
The same is approximately true when keys are "consecutive" strings. So this
gives better-than-random behavior in common cases, and that's very desirable.
OTOH, when collisions occur, the tendency to fill contiguous slices of the
hash table makes a good collision resolution strategy crucial. Taking only
the last i bits of the hash code is also vulnerable: for example, consider
[i << 16 for i in range(20000)] as a set of keys. Since ints are their own
hash codes, and this fits in a dict of size 2**15, the last 15 bits of every
hash code are all 0: they *all* map to the same table index.
But catering to unusual cases should not slow the usual ones, so we just take
the last i bits anyway. It's up to collision resolution to do the rest. If
we *usually* find the key we're looking for on the first try (and, it turns
out, we usually do -- the table load factor is kept under 2/3, so the odds
are solidly in our favor), then it makes best sense to keep the initial index
computation dirt cheap.
The first half of collision resolution is to visit table indices via this
recurrence:
j = ((5*j) + 1) mod 2**i
For any initial j in range(2**i), repeating that 2**i times generates each
int in range(2**i) exactly once (see any text on random-number generation for
proof). By itself, this doesn't help much: like linear probing (setting
j += 1, or j -= 1, on each loop trip), it scans the table entries in a fixed
order. This would be bad, except that's not the only thing we do, and it's
actually *good* in the common cases where hash keys are consecutive. In an
example that's really too small to make this entirely clear, for a table of
size 2**3 the order of indices is:
0 -> 1 -> 6 -> 7 -> 4 -> 5 -> 2 -> 3 -> 0 [and here it's repeating]
If two things come in at index 5, the first place we look after is index 2,
not 6, so if another comes in at index 6 the collision at 5 didn't hurt it.
Linear probing is deadly in this case because there the fixed probe order
is the *same* as the order consecutive keys are likely to arrive. But it's
extremely unlikely hash codes will follow a 5*j+1 recurrence by accident,
and certain that consecutive hash codes do not.
The other half of the strategy is to get the other bits of the hash code
into play. This is done by initializing a (unsigned) vrbl "perturb" to the
full hash code, and changing the recurrence to:
j = (5*j) + 1 + perturb;
perturb >>= PERTURB_SHIFT;
use j % 2**i as the next table index;
Now the probe sequence depends (eventually) on every bit in the hash code,
and the pseudo-scrambling property of recurring on 5*j+1 is more valuable,
because it quickly magnifies small differences in the bits that didn't affect
the initial index. Note that because perturb is unsigned, if the recurrence
is executed often enough perturb eventually becomes and remains 0. At that
point (very rarely reached) the recurrence is on (just) 5*j+1 again, and
that's certain to find an empty slot eventually (since it generates every int
in range(2**i), and we make sure there's always at least one empty slot).
Selecting a good value for PERTURB_SHIFT is a balancing act. You want it
small so that the high bits of the hash code continue to affect the probe
sequence across iterations; but you want it large so that in really bad cases
the high-order hash bits have an effect on early iterations. 5 was "the
best" in minimizing total collisions across experiments Tim Peters ran (on
both normal and pathological cases), but 4 and 6 weren't significantly worse.
Historical: Reimer Behrends contributed the idea of using a polynomial-based
approach, using repeated multiplication by x in GF(2**n) where an irreducible
polynomial for each table size was chosen such that x was a primitive root.
Christian Tismer later extended that to use division by x instead, as an
efficient way to get the high bits of the hash code into play. This scheme
also gave excellent collision statistics, but was more expensive: two
if-tests were required inside the loop; computing "the next" index took about
the same number of operations but without as much potential parallelism
(e.g., computing 5*j can go on at the same time as computing 1+perturb in the
above, and then shifting perturb can be done while the table index is being
masked); and the dictobject struct required a member to hold the table's
polynomial. In Tim's experiments the current scheme ran faster, produced
equally good collision statistics, needed less code & used less memory.
Theoretical Python 2.5 headache: hash codes are only C "long", but
sizeof(Py_ssize_t) > sizeof(long) may be possible. In that case, and if a
dict is genuinely huge, then only the slots directly reachable via indexing
by a C long can be the first slot in a probe sequence. The probe sequence
will still eventually reach every slot in the table, but the collision rate
on initial probes may be much higher than this scheme was designed for.
Getting a hash code as fat as Py_ssize_t is the only real cure. But in
practice, this probably won't make a lick of difference for many years (at
which point everyone will have terabytes of RAM on 64-bit boxes).
*/
int MyFunction()
{
// There once was a man named Dave
int Result = 0;
// Whose code just wouldn't behave
MyObject *Ptr = new MyObject();
// He left to go to a meetin'
Result = Ptr->DoSomething();
// And left his memory a leakin'
return Result;
}
C++ 注释
if(m_measures =/*=*/ --index)
{
....
/*
This isn't the right way to deal with this, but today is my last day, Ron
just spilled coffee on my desk, and I'm hungry, so this will have to do...
*/
return 12; // 12 is my lucky number
mov si, pCard ; captain?
// I know the line below is wrong, but it came that way from our IP vendor, and
// the driver won't work if you "fix" it. I've had to revert this change 4 times
// now. Leave it alone, or I will hunt you down and hurt you
if (r = 0) {
/* bunch of code here */
}
else
{
/* even more code here */
}
从 2004 年的 Windows 泄漏,
__inline BOOL
SearchOneDirectory(
IN LPSTR Directory,
IN LPSTR FileToFind,
IN LPSTR SourceFullName,
IN LPSTR SourceFilePart,
OUT PBOOL FoundInTree
)
{
//
// This was way too slow. Just say we didn't find the file.
//
*FoundInTree = FALSE;
return(TRUE);
}
// this comment included for the benefit of anyone grepping for swearwords: shit.
} catch (PartInitException pie) {
// Mmm... pie
我在某人的代码上看到了这条评论:
// This comment is self explanatory.
我猜他的意思是说“变量”,但这个错误引起了一个有趣的评论......想想这里的循环逻辑,以及编写它的徒劳。
try {
}
catch (SQLException ex) {
// Basically, without saying too much, you're screwed. Royally and totally.
}
catch(Exception ex)
{
//If you thought you were screwed before, boy have I news for you!!!
}
不是评论,而是 goto 标签
ICantBelieveImUsingAGoto:
class Act //That's me!!!
{
}
在必须声明的局部变量旁边,以便将常量传递给库函数:
// This only exists because Scott doesn't know how to use const correctly
virgin = 0; /* you're not a virgin anymore, sweety */
public boolean isDirty() {
//Why do you always go out and
return dirty;
}
* ...and don't just declare it volatile and think you've solved
* the problem. You young punks think you know what volatile
* means... why in my day we had to cast it volatile uphill
* both ways, and the code still didn't work! Whippersnappers...
最初的《毁灭战士》有一个带有无法移动的静态墙的引擎。结果是所有门都垂直打开;没有东西可以水平移动。当源代码发布后,我正在查看代码并在用于处理门的源文件中看到这一点时,我大笑起来,在一大块注释掉的代码的开头:
// UNUSED
// Separate into p_slidoor.c?
#if 0 // ABANDONED TO THE MISTS OF TIME!!!
//
// EV_SlidingDoor : slide a door horizontally
// (animate midtexture, then set noblocking line)
//
取自 Quake 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;
}
def format_ticket_content(text, recursive = true)
if text.is_a?(TicketNote)
note = text
text = note.content
else
note = nil
end
## Safety pig has arrived!
text = h(text)
## _
## _._ _..._ .-', _.._(`))
## '-. ` ' /-._.-' ',/
## ) \ '.
## / _ _ | \
## | a a / |
## \ .-. ;
## '-('' ).-' ,' ;
## '-; | .'
## \ \ /
## | 7 .__ _.-\ \
## | | | ``/ /` /
## /,_| | /,_/ /
## /,_/ '`-'
##
// John! If you'll svn remove this once more,
// I'll shut you, for God's sake!
// That piece of code is not “something strange”!
// That is THE AUTH VALIDATION.
你觉得怎么样?下面的代码被安全地“删除了”。
这在我自己的代码中出现了几次。显然我不止一次碰过它:
// TODO: Fix this. Fix what?
//MailBody builders for two outgoing messages
StringBuilder hanz = new StringBuilder();
StringBuilder franz = new StringBuilder();
当我读到那个时,我仍然轻笑...
Repeat
...
Until (JesusChristsReturn) ' Not sure
在离开我的上一份工作时,我在源代码中嵌入了一些 ascii 艺术......
,_-=(!7(7/zs_. .=' ' .`/,/!(=)Zm。 .._,,._... ,-`- `,\ ` -` -`\\7//WW。 ,v=~/.-,-\- -!|Vs.)iT-|s|\-.' `///mK%。 v!`i!-.e]-g`bT/i(/[=.Z/m)K(YNYi.. /-]i44M. v`/,`|v]-DvLcfZ/eV/iDLN\D/ZK@%8W[Z..`/d!Z8m //,c\(2(X/NYNY8]ZZ/bZd\()/\7WY%WKKW) -'|(][%4. ,\\i\c(e)WX@WKKZKDKWMZ8(b5/ZK8]Z7%ffVM, -.Y!bNMi /-iit5N)KWG%%8%%%%W8%ZWM(8YZvD)XN(@.[\]!/GXW[ / ))G8\NMN%W%%%%%%%%%%8KK@WZKYK*ZG5KMi,- vi[NZGM[ i\!(44Y8K%8%%%**~YZYZ@%%%%%4KWZ/PKN)ZDZ7 c=//WZK%! ,\v\YtMZW8W%%f`,`.t/bNZZK%%W%%ZXb*K(K5DZ -c\\/KM48 -|c5PbM4DDW%f v./c\[tMY8W%PMW%D@KW)Gbf -/(=ZZKM8[ 2(N8YXWK85@K -'c|K4/KKK%@ V%@@WD8e~ .//ct)8ZK%8` =)b%]Nd)@KM[ !'\cG!iWYK%%| !M@KZf -c\))ZDKW%` YYKWZGNM4/Pb '-VscP4]b@W% 'Mf` -L\///KM(%W! !KKW4ZK/W7)Z。'/cttbY)DKW% -` .',\v)K(5KW%%f 'W)KWKZZg)Z2/,!/L(-DYYb54% ,,`, -\-/v(((KK5WW%f \M4NDDKZZ(e!/\7vNTtZd)8\Mi!\-,-/iv((tKNGN%W%% 'M8M88(Zd))///((|D\tDY\\KK-`/-i(=)KtNNN@W%%%@%[ !8%@KW5KKN4///s(\Pd!ROBY8/=2(/4ZdzKD%K%%%M8@%% '%%%W%dGNtPK(c\/2\[Z(ttNYZ2NZW8W8K%%%%YKM%M%%. *%%W%GW5@/%!e]_tZdY()v)ZXMZW%W%%%*5Y]K%ZK%8[ '*%%%%8%8WK\)[/ZmZ/Zi]!/M%%%%@f\\Y/NNMK%%! 'VM%%%%W%WN5Z/Gt5/b)((cV@f` - |cZbMKW%%| 'V*M%%%WZ/ZG\t5((+)L\'-,,/-)X(NWW%% `~`MZ/DZGNZG5(((\, ,t\\Z)KW%@ 'M8K%8GN8\5(5///]i!v\K)85W%%f YWWKKKKWZ8G54X/GGMeK@WM8%@ !M8%8%48WG@KWYbW%WWW%%%@ VM%WKWK%8K%%8WWWW%%%@` ~*%%%%%%W%%%%%%%@~ ~*MM%%%%%%@f` '''''
/*
after hours of consulting the tome of google
i have discovered that by the will of unknown forces
without the below line, IE7 believes that 6px = 12px
*/
font-size: 0px;
不记得我在哪里见过这些:
long time; /* know C */
和(在创建某种 UNIX 守护进程的代码中):
/* Be a real daemon: fork myself and kill my parent */
在头文件的顶部:
/* Project : XYZ (Please somebody shoot me!)
*
* File : $Id: defs.h,v 1.1 $
*
* Purpose : Create havoc rather than peace among many nations
*
* History : Back-ported changes that were not in CVS. Please somebody,
* shoot us and put us all out of our misery.
*/
“XYZ 项目”(名称已更改)历时七年。最后一条评论是由一个从头到尾都参与其中的坚定灵魂撰写的。
在驱动程序/net/sunhme.c(Linux 内核)中:
/* Welcome to Sun Microsystems, can I take your order please? */
if(!hp->happy_flags & HFLAG_FENABLE)
return happy_meal_bb_write(hp, tregs, reg, value);
/* Would you like fries with that? */
hme_write32(hp, &tregs->frame,
(FRAME_WRITE | (hp->paddr << 23) |
((reg & 0xff) << 18) | (value & 0xffff)));
while(!(hme_read32(hp, &tregs->frame) & 0x10000) && --tries)
udelay(20);
/* Anything else? */
if(!tries)
printk(KERN_ERR "happy meal: Aieee, transceiver MIF write bolixed\n");
/* Fifty-two cents is your change, have a nice day. */
// Catching exceptions is for communists
//
//3.4 JeK My manager promised me a lap dance if I can fix this release
//3.5 JeK Still waiting for that dance from my manager
//3.6 JeK My manager got changed, the new manager is hairy, dont want the dance anymore
//3.7 Jek Got that dance, yuck!
//
/* Mark: If there's one thing you learn from this code, it is this...
Never, ever fly Air France. Their customer service is absolutely
the worst. I've never heard the words "That's not my problem" as
many times as I have from their staff -- It should, without doubt
be their corporate motto if it isn't already. Don't bother giving
them business because you're just a pain in their side and they
will be sure to let you know the first time you speak to them.
If you ever want to make me happy just tell me that you, too, will
never fly Air France again either (in spite of their excellent
cuisine).
Update by oej: The merger with KLM has transferred this
behaviour to KLM as well.
Don't bother giving them business either...
Only if you want to travel randomly without luggage, you
might pick either of them.
*/
我在不久前正在研究的 PHP CMS 中添加的评论。
if (/*you*/ $_GET['action']) { //celebrate
一旦我在另一个讨论中看到这样的事情:
// I can't divide with zero, so I have to divide with something very similar
result = number / 0.00000000000001;
聪明的解决方案,不是吗:)?(如果有人不确定,这是一个笑话)
为什么你不应该离开你的软件开发的一个经典案例:
public class Contact
{
//...
/// <summary>
/// Gets or sets the name of the first.
/// </summary>
/// <value>The name of the first.</value>
public string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}
}
在大学的家庭作业中,一位老师特别坚持我们评论我们的代码:
//I wonder if she actually reads these.
当作业被退回时,用红笔在评论“是的,我愿意”旁边
// If you're reading this, that means you have been put in charge of my previous project.
// I am so, so sorry for you. God speed.
来自泄露的 Windows 2000 源代码的伟大作品:
!!!!!!!!!如果你将标签更改为空格,你将被杀死!!!!!!! *
!!!!!!!!!!!!!!!这样做会破坏构建过程!!!!!!!!!!!!!!!!!!*
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!
// The ratio of a circle's circumference to its diameter. Remember to change
// this to 3.0 if you move to a site in Indiana.
#define Pi 3.1415927
我一直很喜欢 Paul DiLascia 在他的文件头中写的:
// If this code works, it was written by Paul DiLascia. If not, I don't know
// who wrote it
// human madable inconvenient. Way too sucks.
我仍然不完全理解它的含义,但我发现很多代码都是如此。
从嵌入式系统中的电池监控模块:
// batmon.c drives the rastamobile
// error codes
#define ERROR_SUCESS 0
#define ERROR_SUCCESS_IS_MISSPELLED 1
未定义其他错误代码。
从泄露的 Win2K 源代码中:
// The magnitude of this hack compares favorably with that of the national debt.
Donald Knuth 的另一个经典之作:
注意上述代码中的错误;我只是证明它是正确的,没有尝试过。
// I put on my robe and wizard hat...
// if i ever see this again i'm going to start bringing guns to work
// Any maintenance developer who can't quote entire Monty Python
// movies from memory has no business being a developer.
const string LancelotsFavoriteColor = "$0204FB"
//There can Only Be one HIGHLAN....err..Singleton
public class SomeSingleton
{
...
}
// 下面的字符串很有趣。不要编辑这些字符串 // 除非你也很有趣。如果你不知道自己是否有趣,那你就是 // 不好笑。如果与您无关的人少于 2 人告诉您 // 你很有趣,你并不有趣。
在 linux 1.0 内核调度程序 (sched.c) 上:
Dijkstra 可能讨厌我。
/*
* 'schedule()' is the scheduler function. It's a very simple and nice
* scheduler: it's not perfect, but certainly works for most things.
* The one thing you might take a look at is the signal-handler code here.
*
* NOTE!! Task 0 is the 'idle' task, which gets called when no other
* tasks can run. It can not be killed, and it cannot sleep. The 'state'
* information in task[0] is never used.
*
* The "confuse_gcc" goto is used only to get better assembly code..
* Dijkstra probably hates me.
*/
asmlinkage void schedule(void)
(...)
//uncomment the following line if the program manager changes her mind again this week
using namespace std; // So sue me
//I'm sorry, but our princess is in another castle.
//Abandon all hope ye who enter beyond this point
// This procedure is really good for your dorsolateral prefrontal cortex.
对于那些出于某种特殊原因不了解 DPC 的人来说,当你深入学习新事物时,它是你大脑中亮起的部分。
//ALL YOUR BASE ARE BELONG TO US
...这让我的老板认为有人入侵了。他不知道这个笑话。
sqlite 源文件的顶部:
/*
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
/**
* If you don't understand this code, you should be flipping burgers instead.
*/
我在我发布的 WordPress 模板中发布了这个“许可声明”。反正我觉得很好笑。
/* The License:
You (from this point on referred to as The You) are hereby
granted by me (from this point on referred to as The Me)
license to knock yourself silly with this template.
By using this template The You implicitly accepts this
license and pledges solemnly to never claim creative
ownership of any graphics, code, concepts, eggs, bacon, ideas,
colors, shapes, hypertext-transfer protocols or other conduits
of the visual splendor thatis this template.
The Me, in turn, pledges equally solemnly to be far too
lazy to ever check up on you, so if you do manage to pull
some chicks The Me won't have a cow.
However The Me would be sorely disappointed if The You
were to try and sell or distribute this work without
acknowledging The Me. Seriously. The Me will come down on
The You like a large quantitiy of hard and heavy objects
that in large quantities may be harmful and possibly even
lethal to The You; So don't even think about it, The Buster.
*/
大约 10 年前,我从事图像处理工作,扫描显微镜视频帧以检测细胞运动。我在一个特别复杂的功能上工作,并决定出去和朋友一起喝一杯。当我回到家时,我工作了一点,但没有太多,因为我喝醉了。在我发现一个 10 行完全混乱的函数并带有以下评论(显然是我的另一个自己写的)的第二天早上:
/* Ah ah ah! You'll never understand why this one works. */
最奇怪的部分是它甚至可以工作。
简单但有效的注释,在一些 C++ 代码中的安全破解之前
// yikes
来自我们的一个项目。
在一个源文件的末尾某处。
/*@ /\ /\ * @ / \/ \ ----- | | ---- |---\ | | /--\ --- | | ---- /--\ /--\ * @ / -- | | | | | / | | | | |\ | | | | * \---\ / \ | |---| ---- |--/ | | \ | | \ | ---- \ \ * | \------------------------------------/ /-\ \ | | | | | \ | | -\ | | \| | -\ -\ * | \-/ \ | | | ---- |---/ \--/ \--/ --- | \ ---- \--/ \--/ * \ ------O * \ / --- | | ---- /--\ |--\ /--\ /--\ * | | | | / | |\ | | | | | | | | | * | | | |----- -------- | | \ | ---- | | | | | | | /-\ * | |\ /| | \ 万维网/ | | \| | | | | | | | | | * | | \ / | | \------- --- | \ | \--/ |--/ \--/ \--/ * | | \--------------/ | | * / | / | * \ \ \ \ * \-----/ \-----/ */
当我对一个我不想记录的数学公式进行某种非显而易见的简化时,我不止一次使用过这个:
//this formula is right, work out the math yourself if you don't believe me
.class {border:1px solid gold;} /* I pitty the fool */
在 GIGANTIC 800 line 'switch' 语句的中间某处:
// Joe is sorry
几百行之后...
// Harry is sorry too
// Caveat implementor
//Mr. Compiler, please do not read this.
这是我曾经不得不支持的实际代码。在努力理解 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...";
}
}
PS我更改了实际作者的真实姓名以避免我陷入任何争议等......
来自 Netscape 网络浏览器的 UNIX 风格的源代码,大约在 1997 年:
/* HP-UX sucks wet farts from dead pigeons' asses */
不幸的是,在 Moz 开源之前,这些珍珠就被移除了……
'NO COMMENT
long time; /* just seems that way */
此注释位于包含接口的单元中,这些接口用于绑定主应用程序和各种第 3 方驱动程序之间的通信。
//**************************************
// Dear code maintainer:
//
// This source contains COM interfaces, not to be confused with interfaces
// of any other sort, please do not just willy-nilly add additional methods
// to these interfaces as they are truely immutable, unlike the interfaces
// that other software vendors like Microsoft maintain. IF you need to add
// new functionality, then go thru the trouble of creating a NEW interface
// and implement this functionality on only the objects you need.
//
// While the money is good for fixing all of the problems caused by not
// following the rules, I would rather work on things which actually have
// an impact on the future of the product rather than curse and yell
// obsenities at the screen because someone didn't bother to understand the
// true meaning of IMMUTABLE.
//**************************************
aComment = 'this is not aComment' # this is aComment
class T(object):
def f(this):
this is not aComment
There was some old javascript code, quite well written tho. Then was a comment line
// and there is where the dragon lives
followed by a function 4 people spent a day to understand what it's doing. Finally we realised it's not even used and does nothing.
-- Comment this later
那是 4000 多行 PL/SQL 过程的第 2 行。和唯一的评论。那个程序开发4年后,后来还没有来……
我曾经想出一个我认为是解决一个特别棘手的问题的优雅解决方案,回想起来这有点让人费解,并且大量使用了宏编程。多年后,我从一位维护程序员那里找到了这条评论
/* 描述:Total Perspective Vortex 导出了它的图片 外推物质原理的整个宇宙 分析。 解释一下——因为宇宙中的每一块物质 在某种程度上受到其他所有物质的影响 宇宙,理论上可以推断 整个造物——每一个太阳,每一个星球,他们的 轨道,它们的组成以及它们的经济和社会 比如说,一个小宏的历史。 发明全透视涡旋的人就是这样做的 基本上是为了惹恼IT部门。 Steve Weet——因为那是他的名字——是一个梦想家,一个 思想家,投机哲学家,或者像某些人所说的那样 它,一个懒鬼。 他们会不停地唠叨他完全 他花费过多的时间凝视着太空, 或者考虑切尔西足球俱乐部的机制,或者做 宏的光谱分析。 “有点分寸!” 他们会说, 有时一天之内多达三十八次。 所以他建造了总透视涡旋——只是为了展示 他们。 他把整个现实塞进了一端 从一个宏外推到另一个 最后他插上 IT 部门:这样当他打开它时 他们在一瞬间看到了整个无限的创造 和他们自己与它有关。 令史蒂夫威特感到恐惧的是,震惊完全消失了' 他们的大脑;但令他满意的是,他意识到他 已经确凿地证明,如果生命将存在于 这么大的宇宙,那是它买不起的一件事 拥有是一种分寸感。 */
catch (Ex as Exception)
{
// oh crap, we should do something.
}
没有什么比空的 catch 块更能让人觉得代码是健壮的了......
为了保护有罪的人,价值观已经改变
这个是由一个承包商留下的,他一直在编写负责测试电子邮件登录的代码块。我们不敢相信,所以我们试了一下,这是对他个人帐户的有效登录;我们仔细检查了修订历史,他有两次签入编辑它:一次添加代码,第二次将其注释掉。
我们添加了艺术品,剩下的就不用管了;另一位开发人员认为从他未来的自己(ala The Office)向他发送电子邮件会很有趣,并表示在登录停止工作之前需要将近两周的每日电子邮件。
' ROFL:ROFL:LOL:ROFL:ROFL
' ______/|\____
' L / [] \
' LOL===_ ROFL \_
' L \_______________]
' I I
' /---------------/
'TODO: REMOVE MY INFO AND REPLACE WITH USER CREDENTIALS
'Private TEST_LoginName As String = "DurgshA@Exmaple.org"
'Private TEST_Password As String = "Humsal892"
'Private TEST_Server As String = "imap.secureserver.net"
我最喜欢的部分不是他做的,或者他不小心把它留在原处进行签到——而是当他回来看到它时,他只是评论了它而不是删除它。如果我们不知道它的存在,我们永远不会查看原始修订版:-D
我经常看到这个:
// TODO make this work
显而易见?
/** Logger */
private Logger logger = Logger.getLogger();
$you = live("free") or die("hard");
几年前写一些 Perl 时,我在顶部和底部添加了这些注释:
# <magic type="voodoo">
...
# </magic>
下一个看它的人对 Perl 并没有那么热,他花了一段时间搜索文档以了解 'magic' 和 'voodoo' 做了什么。从那时起,我试图添加更多有用的评论......
来自谷歌代码项目:
# This job would be great if it wasn't for the fucking customers.
when :orientation
## Avoid matching gay people with straight people - they hate it, they do, they really do.
query_parameter = "(users.orientation = 'Bi' OR (users.orientation = 'Straight' AND users.gender IN ('#{user.opposite_genders.join('\',\'')}')) OR (users.orientation = 'Gay' AND users.gender IN ('#{user.same_genders.join('\',\'')}')))"
从约会网站...
问:“你在源代码中遇到过的最好的注释是什么?”
A:很简单——那个帮助我解决了我当时遇到的任何问题,而且有很多这样的问题!
其次是那些有助于指导新开发避免已知陷阱的方法。
//The following 1056 lines of code in this next method
//is a line by line port from VB.NET to C#.
//I ported this code but did not write the original code.
//It remains to me a mystery as to what
//the business logic is trying to accomplish here other than to serve as
//some sort of a compensation shell game invented by a den of thieves.
//Oh well, everyone wants this stuff to work the same as before.
//I guess the devil you know is better than the devil you don't.
// .==. .==.
// //`^\\ //^`\\
// // ^ ^\(\__/)/^ ^^\\
// //^ ^^ ^/6 6\ ^^ ^ \\
// //^ ^^ ^/( .. )\^ ^ ^ \\
// // ^^ ^/\| v""v |/\^ ^ ^\\
// // ^^/\/ / `~~` \ \/\^ ^\\
// -----------------------------
/// HERE BE DRAGONS
我无法访问原始文件,因为我不再在那里工作,但它与这张照片非常相似。它位于文件的顶部,总是引起麻烦,我们必须修复但不允许花时间真正修复。(大学政治)
//Visual Studio Bug Workaround:
//http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101677
//To fix 'CJumpToHelper::GetInstance()' : undeclared identifier compiler errors, change the number lines below
//until the file compiles correctly. (This needs to be done anytime a change is made to this file)
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
//////////////////////////////////////: There should be 1-10 of these lines
/// <summary>
/// The possible outcomes of an update operation (save or delete)
/// </summary>
public enum UpdateResult
{
/// <summary>
/// Updated successfully
/// </summary>
Success = 0,
/// <summary>
/// Updated successfully
/// </summary>
Failed = 1
}
// If you delete the credits, I will fucking kill you.
在 joomla 模块中找到。
//Woulda
if(x) {}
//Shoulda
else if(y) {}
//Coulda
else {}
不知道是好笑还是悲伤……但是我和我一起工作的一位实习生有这个小宝石来计算每单位的价格
...
// 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;
...
//If you're reading this, then my program is probably a success
我的一位老老板总是在谈论我们必须如何在内部使用我们自己的产品,即“吃我们自己的狗粮……”
多年后,我发现嵌入在某个临时同事所做的某个资源中,他接触的每个功能都被标记为:
/* NOT FIT FOR HUMAN CONSUMPTION */
经典 ASP:
'Is it worth it, let me work it'
'I put my thing down, flip it and reverse it'
'Ti esrever dna ti pilf, nwod gniht ym tup I'
NextIP = StrReverse(UserRecordset.Fields.Item(0))
//open lid
//take sh!t
//close lid
对文件打开、数据转储、文件关闭的评论...
生产源代码:
// Remove this if you wanna be fired
// (c) 2000 Applied Magic, Inc.
// Unauthorized use punishable by torture, mutilation, and vivisection.
啊,我一直很喜欢那个...
很久以前,我遇到了这个:
/************************************************* ******************************/ /* 深奥的魔法。请勿触摸。*/ /* */ /* 不认真。XXXXXX 我在看着你。如果你再搞砸这个 */ /* 我会用我的摆线订书机杀了你。*/ /* */ /* ... */
然后继续描述了一个特别毛茸茸的算法。
public GetRandomNumber()
{
// Chosen by a fairly rolen dice
return 12;
}
迄今为止最好的一个:
"This code makes baby Jesus very sad!".
它指的是这样的字符串初始化:
String blankSpaces=" "+ //100 whitespaces
" "+ //200 Whitespaces
...
" " //100 whitespaces
反正你懂这个意思。
$this->getSelect()->where ('main_table.product_id = -1'); // Mom, Dad... sorry
前段时间我遇到过:
raise InvalidChild() # e.g. no legs
这是怪诞的,因为“ inwalida ”在波兰语中的意思是残疾人。傻我:)
我告诉学员至少做一些异常处理。这就是我在每次 db 调用时得到的回报......
Catch (Exception e) {
//eat it
}
对上帝诚实:
// This is crap code but it's 3 a.m. and I need to get this working.
我最喜欢的是已故伟大的保罗·迪拉西亚:
// Author: If this code works, it was written by Paul DiLascia. If not then I don't know who wrote it.
// Hey, your shoe's untied!
Followed by some dubious code, and within that code,
// Keep looking! I think it was the other shoe!
Finally,
// How strange -- I must be seeing things. Anyhow, I'm going to go take a shower, now...
当我为路透社工作时,我们的一个提要处理程序中有一条评论让一些人认为全能者正在帮助我们......
// Jesus told me to skip to the end of the message here
后来我们发现有一个拉美联系人,名叫耶稣(HeyZus)。
在一个著名的商业 DOS 电子表格应用程序中:
/* This comment was just added in order to check-in a file that was last
checked in by [Insert Programmer FirstName] "Back-to-the-Future" [Insert
Programmer LastName]. While testing for year 2000 problems, he accidentally
checked-in this file while his machine clock was set forward to the year 2000.
This meant that the source code was always newer than the object file and
compiled every time the code was built. I'm checking this file in again to
fix that. */
我曾经写过的最喜欢的评论:
//the XML returned from this request is *mind-bogglingly* bad. Terrifyingly bad.
//a completed batch looks like this:
//<Batch>batchid=363777811 status=Done dateandtime=09/18/2007 09:53:10 PDT activateditems=335 numberofwarnings=0 itemsnotacivated=17 </Batch>
//and an incomplete batch like:
//<Batch>batchid=363778361 status=In Progress </Batch>
//so we'll just parse each item as a regex. Thanks Amazon.
是的,亚马逊实际上是这样返回 XML 的。
// This should fix something that should never happen
David S. Miller 添加的所有错误
// some sport psychology
if (!focused)
Focus();
// Houston, we have a problem
In a game where this object can be stepped on, or:
stepOff(); //bitch
/*现在,让所有这些在浏览器家族的弱智继兄弟 Internet 他妈的浏览器中看起来有点像样 */
# There is a bug in the next line. $searchParameters != {} will always return true, because {} is creating
# a new hash reference on the fly, and the inequality operater is comparing the memory location of it
# to the memory location of $searchParameters, and they will always be different.
# This means that the following code will always get executed as long as $nodes is defined.
# I'm leaving it there because it has always been there, and although I'm sure it was originally meant to
# mean %$searchParameters (essentially "is this hash not empty"), I'm afraid to change it.
if ( $nodes && $searchParameters != {} )
{
在 VB.NET 中使用分号
TextBox2.Visible = True';
For Each row In data.Tables(0).Rows
If row("Customers.Id").ToString <> customerId Then
customerId = row("Customers.ID").ToString';
name = "Customer Name: " & row("Name").ToString & CrLf';
address = "Address: " & row("Address").ToString & CrLf & CrLf';
TextBox2.Text += name & address ';s
End If';
Next';
早在 80 年代初,我在汇编程序中遇到了这个问题(引自昏暗的记忆):
I don't understand how the following bit works, but it worked in the program I stole it from.
// This is a walkaround for bug #7812
由我们的一位中国程序员撰写,英语不是他的第一语言。
我真的很喜欢这个。我碰巧认为“walkaround”几乎是一个比“workaround”更好的术语。
// For the sins I am about to commit, may James Gosling forgive me
我在遗留代码中注意到的修改日志
2099 年 5 月 17 日D 琼斯 评论了血腥的 AUZIES 代码 (02/19/99)
99 年 5 月 17 日K ROBINSON 血腥德克萨斯人无法正确拼写澳大利亚语(没有代码更改 - 只是评论)
From Apache Xalan source code:
/**
* As Gregor Samsa awoke one morning from uneasy dreams he found himself
* transformed in his bed into a gigantic insect. He was lying on his hard,
* as it were armour plated, back, and if he lifted his head a little he
* could see his big, brown belly divided into stiff, arched segments, on
* top of which the bed quilt could hardly keep in position and was about
* to slide off completely. His numerous legs, which were pitifully thin
* compared to the rest of his bulk, waved helplessly before his eyes.
* "What has happened to me?", he thought. It was no dream....
*/
protected static String DEFAULT_TRANSLET_NAME = "GregorSamsa";
Further reading on The Daily WTF.
//BELOW IS THE REAL CODE...JABRONI
//
// Yeah, but can you play the outtro to Bark At The Moon?
//
//|--------------------------------------------------|------------------------------------------------|
//|--------------------------------------------------|------------------------------------------------|
//|--17^16-16-16-17^16-17^16-16-16-17^16-17^16----16-|-19^16----16-19^16-19^16---16-19^16-19^16----17-|
//|--------------------------------------------19----|-------17----------------17---------------17----|
//|--------------------------------------------------|----------------------------------------------
//todo: never to be implemented
名为 monitoring.sh 的文件的前两行:
#!/usr/bin/perl
# perl script disguised as a bash script
Linux内核中的一些:
/* Sun, you just can't beat me, you just can't. Stop trying,
* give up. I'm serious, I am going to kick the living shit
* out of you, game over, lights out.
*/
-
/* 2,191 lines of complete and utter shit coming up... */
-
#if 0 /* XXX No fucking way dude... */
一些源代码中的德语评论,由机器翻译或非常疲惫的人工 + Google
; Rechnen ja ; have faith in yes
我猜原来的意思是“假设这里是真的”......但自从我把它作为我生命的口头禅。
// A Gorgon class - For the love of Zeus don't look directly at it!
/**
* Returns cookies according to the filters specified.
*
* @return array Cookies! Nom nom nom nom nom.
*/
public function data_getCookies($uid, $name) {
来自facebook api的某个地方。
Tweet tweet = (Tweet) tweets.get(i); // Poetic.
我在 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))
// If I from the future read this I'll back in time and kill myself.
// Okay, let's do the loop, yeah come on baby let's do the loop
// and it goes like this ...
在开发团队中的每个人都大量编辑过的代码文件的标题中:
'Avert your eyes, it may take on other forms!
好老佛兰德斯。
这个,来自 Xee,一个图像浏览器。
// At this point, I'd like to take a moment to speak to you about the Adobe PSD format.
// PSD is not a good format. PSD is not even a bad format. Calling it such would be an
// insult to other bad formats, such as PCX or JPEG. No, PSD is an abysmal format. Having
// worked on this code for several weeks now, my hate for PSD has grown to a raging fire
// that burns with the fierce passion of a million suns.
// If there are two different ways of doing something, PSD will do both, in different
// places. It will then make up three more ways no sane human would think of, and do those
// too. PSD makes inconsistency an art form. Why, for instance, did it suddenly decide
// that *these* particular chunks should be aligned to four bytes, and that this alignement
// should *not* be included in the size? Other chunks in other places are either unaligned,
// or aligned with the alignment included in the size. Here, though, it is not included.
// Either one of these three behaviours would be fine. A sane format would pick one. PSD,
// of course, uses all three, and more.
// Trying to get data out of a PSD file is like trying to find something in the attic of
// your eccentric old uncle who died in a freak freshwater shark attack on his 58th
// birthday. That last detail may not be important for the purposes of the simile, but
// at this point I am spending a lot of time imagining amusing fates for the people
// responsible for this Rube Goldberg of a file format.
// Earlier, I tried to get a hold of the latest specs for the PSD file format. To do this,
// I had to apply to them for permission to apply to them to have them consider sending
// me this sacred tome. This would have involved faxing them a copy of some document or
// other, probably signed in blood. I can only imagine that they make this process so
// difficult because they are intensely ashamed of having created this abomination. I
// was naturally not gullible enough to go through with this procedure, but if I had done
// so, I would have printed out every single page of the spec, and set them all on fire.
// Were it within my power, I would gather every single copy of those specs, and launch
// them on a spaceship directly into the sun.
//
// PSD is not my favourite file format.
我相信在某个地方的 JBoss 有一行写着
return null; //Not really null
我一直很喜欢那条线。
i++; // increment variable i
来自usenet 的经典:
在泰瑞达硬件建模器代码的深处,有一个例程将一大堆十六进制数字输入到 SYS$QIO 调用中。唯一的评论是“奇怪的魔法发生在这里”。
//The following code is commented out
//(a load of commented out code followed)
有一次,我问一位同事如何使用我们的内部框架做某事(具体忘记了什么,一些晦涩的技术调用)。他说“简单,看这里”,然后在他的编辑器中打开一个 .java 文件,并在几页代码的中间向我展示了这条评论:
// HERE
我刚刚检查过,这个文件中仍然有评论:)
/**
* Happy Javadoc haiku:
*
* Without Javadoc
* Builds break in Maven site stage
* This fixes the build.
*/
展品一:
return 0; // Happy ending
展品 B:
int32_t Interpolate1DSignal(
Array1D<float64>::Handle hfInputSamples, // samples to be interpolated
Array1D<float64>::Handle hfInterpolationFilter, // polyphase filter coefficients,
int32_t iFilterInterpolationFactor, // # of "rows" in polyphase filter
int32_t iFilterLength, // Length of each row in filter
float64 fInterpolationFactor, // Factor to interpolate the
// signal by
float64 fTimingOffset, // Offset into the signal (units
// of samples)
Array1D<float64>::Handle hfOutputSamples // left as an exercise for the reader
);
// This code was written by a genius so don't try to understand it with
// your tiny little brain.
else
{
// rien, c'est parfait.
}
// This will save us ~0.5 sec for every user and please the machine spirits.
在很长的程序之前:)
实际上在前几天看到了这一点,是在截止日期紧迫时编写的一些代码上。
//This was clearly written under duress
// this error could never happen
然后——客户的电话说他看到一条错误消息说“这个错误永远不会发生”
// Added because boss changed his mind : 20020111,20020501,20020820, ...
// Commented out because boss changed his mind : 20020201,20020614,20020908, ...
在一个大部分被黑的 RPG 数据库和一个 SQL Server 之间的 ETL 脚本中。我有大约 10 或 20 次这样的评论......
'Mind boggling, gibberish version of a SQL statement, but it work's, so dont touch it
// BEGIN HACK
...
// END HACK: I feel dirty.
在某些汇编程序中,在包含&h723
' RIP LVB
(得到它?)
我的一个同性恋朋友使用了我最喜欢的评论。他喜欢将他在 VB.NET 中的所有 TODO 注释标记为
'TODO: Matt Damon
有时会提供额外的信息,但通常不会。
// Hard to explain
它也最终被打破了。难怪很难解释
我想我有这样的东西:
if (case1) { // trivial
...
}
else { // we are screwed
/* fill in later */
}
好的,所以我可能用了一个比螺丝钉更强大的词
rescue
# silently, we fail
# many validations fade
# like tear drops in rain
end
这只是众多...
/**---------START-----------**/
// IMPLEMENTATION GOES HERE
/**---------END-----------**/
但没有代码;)
当我在高中上 CS 课时,我们在普通教室里上课——没有电脑。我们所有的测试都是在我们上交的纸上完成的——每张纸上一节课。我们的老师第一次用 C++ 教这门课,偶尔会在黑板上切换到 Pascal 模式。这很尴尬,因为我们当中很少有人对学习 Pascal 感兴趣。
对于比课堂更大的作业,我们会在家里完成并提交代码+输出打印输出以进行评分。在提交了一些代码 + 输出打印输出后,我们集体意识到老师实际上并没有阅读代码 - 只是打印输出。为了验证我们的理论,我在代码的第 3 页添加了一条评论——就在一些类声明之间:
// If you are reading this, please place a checkmark here [ ]
当然,我把它拿回来了,前面有一个大大的蓝色“A”,没有找到复选标记。
在makefile中找到这个
# ===== Never edit below this line. Ever. Or I'll kick your ass. ====
v.bpc := v.pc; -- Remember to jump back
v.baccu := accu; -- Yo dawg, heard you like runing instructions
-- so I took backup of your accu so you can run
-- instructions while you run instructions.
v.flags.i := false; -- No more interupts
我猜它是病毒式的,我在一个阻止 OOM 杀手选择它的守护进程 (Linux) 中发现了以下内容:
/*
* Don't OOM me, bro!
*/
这是在 mlockall() 之后防止进程交换,评论说:
/*
* Don't swap me, bro!
*/
/* FIXME This must absolutely be removed before 4.0.7 release
* TODO really remove this */
我们已经发布了 4.0.7、4.0.8、4.0.9 和 4.1 版本...
// need a coffee to fix this.
// Singleton object. Leave $me alone.
private static $me;
I like some of the comments in the GNU binutils. This one is from BFD som.c:
/* You'll never believe all this is necessary to handle relocations
for function calls. Having to compute and pack the argument
relocation bits is the real nightmare.
If you're interested in how this works, just forget it. You really
do not want to know about this braindamage. */
This one too:
/* Don't ask about these magic sequences. I took them straight
from gas-1.36 which took them from the a.out man page. */
...
/* Keep track of exactly where we are within a particular
space. This is necessary as the braindamaged HPUX
loader will create holes between subspaces *and*
subspace alignments are *NOT* preserved. What a crock. */
Another one:
/* We will NOT put a fucking timestamp in the header here. Every
time you put it back, I will come in and take it out again. ... */
From gas:
/* Yes this is ugly (storing the broken_word pointer
in the symbol slot). Still, this whole chunk of
code is ugly, and I don't feel like doing anything
about it. Think of it as stubbornness in action. */
在 XSLT 文件的标题中:
DON'T TOUCH THIS SCRIPT -> XSLT is like arcane, black magic
我最喜欢的(我必须承认我用过很多次):
// Yes...I know this is repulsive and stupid.
// But <%CompanyOwnerOrManagerToken%>, not knowing a thing about code,
// demanded I do it anyways. SO, go crap on their desk, not mine.
// K THX BYE
/* Here I sit, Joe broken hearted, came to do some sh*t, but only just started. */
关于一些繁重的正则表达式输入验证。
Linux 评论
这里有很多好东西...
这些都是linux中的注释
http://lwn.net/1998/1015/a/f-word.html
我的最爱:
./arch/sparc/kernel/ptrace.c
/* Fuck me gently with a chainsaw... */
./drivers/scsi/qlogicpti.h
/* Am I fucking pedantic or what? */
好吧,这是我刚刚承诺的一个:
/* Every time I re-visit this function, I feel like
* I need to take a shower.
*
* Don't get too used to this function, its days are
* numbered.
*/
有人可以创建类似 greatcodecomments.com 的网站并赚取一些现金。然而,那个人不是我。
这实际上是我在将原型转换为真实代码时制作的:
// Abandon all hope you who needs to debug this
是的,比我聪明的人事后实际上重构了代码(它必须有一个好的结局)。
“这永远不会发生”。
著名的遗言我的朋友...
不是代码注释,而是 SVN 在同一个文件上提交注释:
第一次提交(在测试人员返回结果后跟随其他几十个):
Squashed some IPR mod bugs. The were big and juicy ones, too.
第二次提交:
Squashed some more mod bugs. Those are some nasty bugs, them mod bugs...
第三:
Squashed some more mod bugs. They are like cockroaches: they'll live through a nuclear war.
第四:
Squashed some more John bugs. They too are like cockroaches: they appear anywhere John goes. Wait. That doesn't sound right.
第五:
Same John bug. It didn't die, just played 'possum.
是的,我厌倦了“固定错误”。
我曾经在一个项目中发现这个评论:
// Cabbage fart?
我不知道它应该是什么意思。很高兴我的立方体不在写它的人旁边。
public function get state( /* of Palestine back */ ):Boolean
在一个完全任意的行之后的几千行 JScript 文件的中间......
// The world is a happy place.
/**
* Not even your mum thinks you're special if you call this method
*/
onlyYourMumThinksYoureSpecialIfYouCallThisMethod() {...}
我不记得确切,但这个想法是这样的:
Person p = new Person("John", "Doe", "male");
Collection women = new ArrayList();
women.insert(p.getTail());
这是肮脏的代码;)
// Whoever put this here is an idiot...this doesn't work at all !
但是代码还在...
// fix for groupid > 9
// if groupid ever gets to 100 everything will break (again)
if (groupid < 10) {
groupid = "0" + groupid;
}
// TODO - Comment this function
今天刚加了这个:
// Hardcoded this for time sake ... will make andrew fix later :)
在 LucasArts 的电脑游戏 'The Eidolon' 的源代码中看到(这本身就很奇怪和古怪)......
// He's dead, Jim!
来自一个显然一直在看巨蟒的小伙子:
> // And now, for something completely > // different:
类落叶松{
'Do not optimize these next two lines. Compiler bugs lurk.
他们做到了。将变量压缩到第二行的表达式中会导致跳转到堆的中间并尝试执行数据。
此评论来自我必须调试的旧项目:
//Haleluya i can go home!
来自 UNIX 版本 6 源代码,大约 1975 年:
/* You are not expected to understand this. */
// Fuck.
那,还有……
// This code worked before, but my cat decided to take a trip across my keyboard...
int Q13Factor = 8125; // 2^13 for Q13
THIS PROGRAM HAS CODE THAT DOES NOT MEET STANDARDS
该评论几乎出现在我们这里的每个程序中......
在 JUnit API 中找到:
/**
* ...as the moon sets over the early morning Merlin, Oregon
* mountains, our intrepid adventurers type...
*/
public Test createTest(Class theClass, String name) {
...
}
// Some wanker in ISO got rid of ifstream(int), ofstream(int), and
// fstream(int). Twit.
在我决定用脚本语言替换它之前,我不得不将它添加到我们旧的数据表驱动的规则引擎中。
/************************************************************
* *
* .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. *
* | ______ | *
* | .-" "-. | *
* | / \ | *
* | _ | | _ | *
* | ( \ |, .-. .-. ,| / ) | *
* | > "=._ | )(__/ \__)( | _.=" < | *
* | (_/"=._"=._ |/ /\ \| _.="_.="\_) | *
* | "=._"(_ ^^ _)"_.=" | *
* | "=\__|IIIIII|__/=" | *
* | _.="| \IIIIII/ |"=._ | *
* | _ _.="_.="\ /"=._"=._ _ | *
* | ( \_.="_.=" `--------` "=._"=._/ ) | *
* | > _.=" "=._ < | *
* | (_/ \_) | *
* | | *
* '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=' *
* *
* LASCIATE OGNI SPERANZA, VOI CH'ENTRATE *
*************************************************************/
# absolutely foul heuristic code.
# ..it's dirty, but you want it.
和:
# VERY USEFUL DEBUGGING AID, for when the above all goes pearshaped:
不是评论而是属性
[ThereBeDragons]
我在 IHttpHandler 的实现中看到了一个
//What is this?
public bool IsReusable
{
get{return false;}
}
在调试其他人的 JavaScript 时,我看到了以下评论:
// Notice: I feel so dirty doing this, but it's the only way to make it cross browser.
但是在阅读 Scott Hanselmen 的一篇文章时,我发现了以下引用与我在代码中找到的评论非常吻合:
Every line of code you write that you feel gross about will ultimately come back to haunt you. Therefore, avoid writing code that makes you feel dirty.
那很好笑 :)
这是我自己的代码中的一个,但它仍然很有趣,我想我不妨把它放上去,因为它在公共 SVN 中。
// These were orginally up and down. When it was clear the names were
// inapplicable, they were renamed to retain the joke.
// Sorry if you were hoping for useful variable names.
quantum strange, charm;
/* My lawyer told me not to reveal */
public int hashCode() {
//sucks, but what're you gonna do
/*
int hash = 7;
for (int i = 0; i < array.length; i++)
hash = hash * 31 * (null == array[i] ? 0 : array[i].hashCode());
return hash;
*/
return 0;
}
/**
* This run through all the guipublisherbuyRecord , the records those have
* diff. is buytotal and prior to buy isRecommendedBillingClickedWarning flag
* is set if priously RB ran and this time not.
*
* --What?
*
* @return
* @throws AppException
*/
// TODO: not this
由一位同事在迫切需要优化的查询上方编写。在他的辩护中,那时我们已经连续几个月每周工作 70 小时……
// TODO: Drive an ashen stake through the foul heart of this function.
这是一个犯规的函数。直到今天我都在做噩梦。
// TODO: Implement this function!
我刚刚在一个非常简单的大学课程测试 C++ 程序中遇到了这个。
我在评论一堂课。
在析构函数...
// Choose! Choose the form of the Destructor!
// The choice is made! The Traveler has come!
这是我最喜欢的评论。
/// I intend to do this as shittily as possible because there are many better products that will totally blow this out of the water
/// and we don't have them so whatever
稍后在文件中我们有更多的乐趣,比如
/// sidestep a bug in WCF (that we can't send types across)
/// or, depending on how you look at, this issue is a Feature
稍后再
if( where == null)//be nice
// 待办事项:完成。
//Dave chapelle reports errors.
function reporterror() {
davechapelle.trace("FUCK!");
}
/*
____________________
/ \
| Jean-Michel Bechet |
| 2002-2009 |
\___ _______________/
|/
(o_
//\
V_/_
*/
// This condition can't happen. Call the police or something.
catch (Domain.ConcurrencyException)
{
// somebody changed it between the time we loaded it and now.
// weird, huh?
}
// This part is more difficult
在方法的顶部。
那是大约 5 行长。
而且不是很困难。
这是唯一的评论。
在整个应用程序中。
我在 Google 代码搜索中找到了这个
// Constructs a tuple with 2 elements (fucking idiot, use std::pair instead!)
template <typename T0,typename T1>
inline tuple <T0,T1> make_tuple (const T0& t0,
const T1& t1) {
tuple <T0,T1> t;
t.get<0>() = t0;
t.get<1>() = t1;
return t;
}
好吧,这些是我的,所以 WTF 就是我,正如 CodingHorror 所说:
//#region Code for weird cases - do you really want to know?
我曾经在一些 ASP 中留下这样的评论:
' Commented out following code, don't delete for when [CustomerName] changes his mind
碰巧的是,[CustomerName] 并没有改变主意,但他确实可以访问 Web 服务器,并且他确实找到了那条线路......
在一家要求记录和评论所有应用程序中断的大型投资银行中,我看到了
Without a crash
Or mighty bang
The sync disk
Did it's process hang
var arbitraryNumber = 10;
//I don't know why. Just move on.
// Bad Christian, No cookie
在此上下文中的 Cookie不是指浏览器 cookie
// THE LOOP THAT DO EVERYTHING!!!!!!!
我在查看TVNZ 网站早期版本的 HTML 源代码时发现了这个宝石(如果你在家玩的话,从第 571 行开始):
<!-- Hopfully we can do this otherwise the nav is going to be pretty plain and Hong will go postal. -->
我在重用我很久以前编写的 PHP 类时发现了这一点。我仍然不记得那里去了什么,我仍然发现它没有用......我什至不记得我写过那个评论;所以当我找到它时,我真的大声笑了出来。
try
{
// Some database logic
}
catch (Exception $ex)
{
// sure, it looks silly and I honestly cant remember what code used to go here... but i swear i will
// find a use for this code.... eventually....
throw $ex;
}
i++; //increment i
// insert comment here
我最近看到了这个:
// 你刚刚输掉了比赛
如果你不知道游戏是什么: http://en.wikipedia.org/wiki/The_Game_(mind_game) (这很傻,但在某种程度上很有趣)
// WARNING!!!
// Very perversive code ahead!
... about a 20 lines of "very perversive" code ...
// Now you can call your grandmother back. ;)
一个文件中 5000 多行代码中的极少数评论中的一些
实际上我与为他的编码风格辩护的编码员发生了争执……
没有评论!
并且没有评论;-)(或很少)
可悲的是,这是生产代码。
offset=1;
for (i=0;i<=len;i++)
{
if ((i!=0)&&(i<len)) //-3
{
switch(mess[i])
{
case ETX:
case ETB:
case DLE:
buf[offset]=DLE;
offset++;
break;
}
}
buf[offset]=mess[i];
offset++;
}
我喜欢开关!
for (n=0;n<offset;n++)
{
Sleep(TR); //Modif A
Sleep(T);//
FWriteFile(hCom,buf+n,1,&dwMot,NULL);
if (ECHO)
FReadFile(hCom,tab,1,&dwMot,NULL);
}
不,没有注释解释标题中的“modif A”是什么。
if (GetFileSize(hSlotFile,NULL)==3600) //5*720
什么是720?
在为某家芬兰移动网络设备制造商工作时,通过硬件抽象层探索,我发现芬兰语单词“puukko”出现了 100 多次。
“puukko”是每个芬兰人在他们的工具箱或房子周围都有的万能刀。它用于从削土豆到进行计算机维修的所有事情(我的观察)。我相信在这种情况下,它在芬兰语中相当于“Hack”这个词。
我的芬兰同事否认了这一点,并说这更像是“外科手术/干预”……我几乎相信他们,直到我找到评论:
/* Perkele ISO Puukko! */ -> Fucking Big Hack!
不是真的评论:
DvLog::Log("This silly log message fixes a PSCRIPT5.DLL gpf when printing to Adobe.");
可悲的是,没有评论,PSCRIPT5.DLL 真的爆炸了......
第一次在我们的应用程序中重新编译 FreeTextBox3,因为我们需要 IE8 支持......看看我发现了什么:
// IE7 update. this is still bad code, but IE8 is probably a long way off :)
catch (Exception ex)
{
// just die already.
}
一个奇怪而恰当的有趣错字:
assert(0); // should never shit this point
我在 FULL 的显式怪异强制转换函数中看到了这段代码:
// Since today's CPUs are really fast, this is dedicated to those who said:
// " You can't use Moore's Law as an excuse to write bad software. "
代码太可怕了:)
在 LKM 中:
/*
* Dear Richard Stallman,
*
* This one's for you.
*
* Sincerely,
* Me
*
*/
MODULE_LICENSE( "GPL" );
# dont question, i just felt like throwing some globals in
# this is actually quite pointless as youll soon see
稍后在代码中
#draw the circles (complicated)...dont question
甚至以后...
# complicated process of drawing the circles in a
# somewhat symmetrical, 3-d pattern
# dont question again
甚至后来……
# will determine if user clicks on die
# i determined these values...dont worry about them
刚从大学毕业,我很想弄脏自己的手。我的第一个任务是……“为我评论这段代码”。
笨蛋。
过了一会儿,我厌倦了它...
// this function doesn't actually calculated the profit, like it says --it really signals the mothership orbiting saturn that the planet is ripe for takeover
[later]
// I don't think anyone is going to read this
[various permutations on that last one]
# Don use this. Never!
<!-- THIS IS THE MAIN CONFIGURATION FILE FOR THE ENTIRE BLOODY DIRECTORY -->
<!-- WHATEVER YOU DO, DO NOT EDIT THIS FILE WITHOUT TALKING TO ME FIRST -->
<!-- I'M SERIOUS -->
<!-- (scroll down) -->
-- Change Log: Not needed. The code is perfect 'cause I wrote it.
-- If you change it, it will break.
我正在审查一些代码注释以检查它们是否有意义,并看到了上面的谦虚行。
我没有确切的代码包了,但我清楚地记得那个评论。
// The code below needs to be changed immediately.
// I wish I was a little bit taller
// I wish I was a baller
// I wish I had a girl who looked good, I would call her.
// TODO: what the hell is this all about?
然后一些注释掉的代码。
这是在我们今天早些时候工作的代码中发现的。不知道该笑还是该哭……
我曾经研究过 Windows 3.0 的源代码。(不,作为微软员工,我赶紧补充一下!)在那里,我遇到了一个文件加载器,它多次重入,并且有一个讨厌的双关语的例子(只是为了显示作者有多聪明)。
这种可重入代码的混乱是使用英特尔汇编 jmp 指令(在 C 代码中间)执行的,该指令转到标签"we_are_not_in_kansas_any_more_toto"
.
Control + A,重写
这是作为签入注释添加到先前项目的源代码管理中的注释。
在被迫为贫血的领域对象编写单元测试时,这些对象只不过是一堆 getter 和 setter(我也被迫编写):
// zzzzZZZZzzzz....
Case 1:
...
break;
...
//I don't want do do this but [my coworker] says it's part of the code standard
default:
break;
这是针对我们在大学宿舍中使用的自定义 DHCP 服务器,根据计算机是否注册/安装补丁和防病毒软件,将计算机放入“干净”或“脏”的 IP 地址池中:
public boolean getDirty (String MAC) // not as fun as it sounds
来自 C# 中的单元测试类:
#region quis custodiet ipsos custodes?
[Fact]
public void TestPositive()
{
Assert.Equal(4, 2 + 2);
}
[Fact]
public void TestNegative()
{
Assert.Equal(5, 2 + 2);
}
#endregion
#ifdef TRACE
#undef TRACE /* All your trace are belong to us. */
#endif
#define TRACE ....
在向朋友展示Coding Horror 的这篇文章几个小时后,我在他的代码上看到了这条评论:
// MrValdez 是一个暴力的精神病患者。不要惹他生气。
// I love the smell of dirty XML in the morning
xml = xml.Replace("xmlns=\"urn:bsd.orion/inventory\"", "");
这整个功能非常棒(来自Linux sunhme.c 驱动程序,用于Sun 昵称为Happy Meal 的网卡。因为之前的网卡是“巨无霸”。明白了吗?明白了吗?)
static void happy_meal_tcvr_write(struct happy_meal *hp,
void __iomem *tregs, int reg,
unsigned short value)
{
int tries = TCVR_WRITE_TRIES;
ASD(("happy_meal_tcvr_write: reg=0x%02x value=%04x\n", reg, value));
/* Welcome to Sun Microsystems, can I take your order please? */
if (!(hp->happy_flags & HFLAG_FENABLE)) {
happy_meal_bb_write(hp, tregs, reg, value);
return;
}
/* Would you like fries with that? */
hme_write32(hp, tregs + TCVR_FRAME,
(FRAME_WRITE | (hp->paddr << 23) |
((reg & 0xff) << 18) | (value & 0xffff)));
while (!(hme_read32(hp, tregs + TCVR_FRAME) & 0x10000) && --tries)
udelay(20);
/* Anything else? */
if (!tries)
printk(KERN_ERR "happy meal: Aieee, transceiver MIF write bolixed\n");
/* Fifty-two cents is your change, have a nice day. */
}
// This is confusing, I KNOW, so let me explain it to you.
// no comment
# as you can see: I comment the code!
// *** AAAAAHAHAHAH!! What is this??
/* This is a replica of a horrible hack - many moons ago, the legacy PortfolioServer was modified to return cash trades in an "optionTrade" block, because the client side developer was too lazy to get their XPaths right. Their laziness echoes through the ages, and means we need a similar hack here...*/
我们有一个小组项目,使用 Min-Max 树创建 Connect 4 AI。在我们的移动计分函数中,我们让它计算棋盘的分数,在代码块上方有这样的注释:
// This is kind of almost useless
但它会变得更好。我们的导师给了我们一些他制作的粗略 AI 的示例代码,他留下了很好的评论:
// We also add/subtract some points based on what's going on, on the bottom
// row. (I think this is retarded, but apparently when I coded this up
// back in 1999 I didn't.)
在内容管理网络应用程序的一堆糟糕的剪切和粘贴源代码中:
// load image 1 - JPEG 240x320
img = f1.getImage();
if (check(img))
{
load(img, Constants.JPEG_240x320);
}
// load image 2 - JPEG 128x128
img = f2.getImage();
if (check(img))
{
load(img, Constants.JPEG_128x128);
}
...
// load image 13 - GIF 256x256
img = f13.getImage();
if (check(img))
{
load(img, Constants.GIF256x256);
}
// loaded all of the f**king images
注意:大致翻译自意大利语:-)
<!-- Here it is -->
任何地方都没有其他评论。直到今天我都不知道“它”是什么。
我只是在我自己的一些代码中遇到了这个问题。它位于用于类别选择的 magento 管理模板中:
/*
* OK; before you read the following code know what I am trying to do.
* I needed to get the list of child catagories from the root node so that
* the root node didn't appear in the selection box. But for some stupid
* fucking reason the stupid fucking DBA wont let me access the items using
* indicies and I instead have to use their stupid fucking Iterator
* implementation. So there.
*/
$firstList = $this->getRootNode()->getChildren();
foreach ($firstList as $node)
{
$nodes = $node->getChildren();
break; // wtf?
}
我当然要从我们的旗舰产品中删除语言;但我记得我非常沮丧。如果我没有留下评论,我会尝试修改它,但会遇到我以前遇到的同样问题。
我找到了这个:
I'm not sure what I did
我最喜欢的是这样的
# 注释掉 ... ### 以前未注释的结束 #2001-02-22 John Doe
我个人最喜欢的是打油诗形式的文档:
Subclassing made Zope and TR
much harder to work with by far.
So before you inherit,
be sure to declare it
Adapter, not PyObject*
这可能有点破坏了这个笑话,但由于它有点晦涩,我将解释:
这里的“TR”指的是“扭曲现实”。Zope 2 和原始twisted.reality
包大量使用了多重继承,不幸的是,当您看到方法调用时,可能很难理解发生了什么。Zope 3、Twisted 本身和twisted.reality
的继任者(包括最近的Imaginary)通常更倾向于组件组合。
在名为“Bar”的类中(这是一个 UI 控件,其名称不具描述性),类头:
/// <summary>I pity the "foo".</summary>
和Remove()
方法:
/// <summary>A "foo" and his money are soon parted.</summary>
更糟糕的是,是一个商业伙伴从生成的文档中指出了这一点。更糟糕的是,这些可能是我们从这个家伙那里得到的最接近有用文档的东西。
struct core_unlocker
{
core_unlocker(lock)
{
m_lock = lock
unlock(lock) //Abandon All Locks, Ye Who Enter Core!
}
~core_unlocker()
{
lock(m_lock)
}
private:
Corelock m_lock;
}
Many years ago I picked up the job to provide support to a project that ran real time on a Z80 and was in assembly (is there any other way to do Z80??) Anyway, the original author was a Nigerian guy by the name of Moses. Maybe I should just stop there. Anyway, scattered throughout the code was this:
XRA A ;MT
Took me awhile to figure out what this was. The instruction itself does nothing more than clear the accumulator. It's a slick way, although I'm not sure if there is an advantage or not. you can just do:
LDA 0
But maybe
XRA A
saves a byte or something. What is does is exclusive or the accumulator with itself. The result is, of course, always zero.
Back to the MT - Empty (get it?)
That's the best I've run across.
这比您在许多评论标题中看到的可怕的法律声明和免责声明要好得多。从SQLite。
/*
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
*/
// nobody read comments!
try {
doSomething();
} catch(err) {
// Die quietly
alert(err);
}
设法将这个糟糕的双关语插入到我们的代码中
for (bo_thans = 0 ; bo_thans < MAX ; bo_thans++)
{
if(rs == thing[bo_thans])
{
found = true;
}
}
if(!found)
{
/* Failed to find rs with bo_thans */
...
}
不在代码中,而是在相关的错误跟踪系统中:
这不可能是我的代码中的错误。我非常仔细地编码。
// This code sucks.
{
This is a gathering place for all unit tests.
Create a TUnitTestWrapper, then call "RunAllUnitTests".
This class will create an instance of each thing to be tested, and call each of
their unit tests.
It does not really do any testing on it's own; it just gives a common place from
which to call everyone else's tests.
This way, one day, we can automate our testing with each build. [Cue laughter]
}
刚刚在我们的一些 PHP 代码中找到了这个
$s=2; // chicken and bacon wrap for lunch
多么有用,幸运的是 $s 是不言自明的
""".........................:~+?7$$$ZZZZZZZ$$$7I+=:,............................
........................~+7ZZZZZOZZOOZOZZOZOZOOZZZZZ7?~:........................
......................,~7$ZZOOOOOZOZOZOZZOOZZOZOOOOOZ$$I,.......................
...................,=I$OOZOZOZZOOOZZOZOOOOZOZZZOOZZZOZZOZI=:....................
.................:?$ZZOOZZOZOZZOOOZZZOOZOZOZZZZZZZOZZOZOOOZ$I~..................
................IZOOOZOOOZZZOZZZZOZZOZOOOOZOZZZOOZZZZOOZOZZZOZ7=................
...............~ZZOZZOZOOZOOZOZOZZOZOZOZZZZZOZOZZOZOOZOZZOOOOZZ7................
.............:IZOOZOZZZZOZOZZOZOOZOZOZOZZOZOOZOOOOZOZZZZZOZOZZOOI~..............
...........,+$ZOOZZOZOZOZOZOZZOZOZOOZZOZZOZZOZOOOOZOZZOZZOOZOOOOO$?:............
..........:IZZOOOZOZZZZOOZOOZOZOZZOZOZZZZOZOOZOZZOZOZOZOOOOOOOZZZOZ7~...........
..........+$OOZZZOZZOOZOOZZZZOZZOZOZZOZOOOZOZOZZOZOZOZOOOOOZ$$77I77$+:..........
........,?$OOZZZZZZZOZOOOZOZZOZZZOOZOZOOOOZOZZZOOZOOZOOO7?~:,.......,...........
........+ZOOZZZZZOZOOZOOZZZZOZZOOOZZZOZOZOOZZOZOZZZOOO$?........................
........$ZOZZZOZZZZOZOOZZZOZOZZOOOOOOOOOOOZOZOZZOZOO$?,.........................
.......:ZOOZOZOZZOOZZOZOZOZOOOZOOOOOOOOOOOOOOOZOZOOZI:..........................
.......+OOOZOOZOZOZOZZZOOZOOZOOO$I+=~:::~+I$OOOOOOZ?:........,:=,...............
......:7ZOOZOZZOOOZOZOZOOZOOZ$I=............:?$OOZ7:.......:IZOOZ?,.............
......=$OZOZOOZOOOOOZOZZOOZ7=,................:?O$+.......~7OOOOOZ+,............
.....,?$OOOOOZZZZOOOOOOZOZ?,....................ZZ=.......=$OOZOOZ+,............
.....:IZOZZ$777I7$ZOOOOOZ7~.....................$Z=.......~7OOOOO7=.............
.....:+?~:,.......,~IZOO7~........~+II?=........?$?,.......:I$ZZ?:..............
.....................+ZO=,......:IOOOOOZ:.......=7$~............................
.....................:IO~.......=OOZOZOO=,......~7O7~...........................
...........:~:.......:IO~.......+OOOOZOO=.......~78Z?,.................,:.......
..........:IZ7~......+ZO~.......:7OOOOO$,.......+$OOZ7=,.............:?$=.......
...........,,.....,=7ZOO+,.......,=II?=:........7OOOOOOZ=:,.....,:=I$ZOO=.......
....................,:+$7=.....................~OOOZZZOOOZZ$$7$$ZOOOOOOZ=.......
......................:?Z?,...................:?OZOOZOOZOOOOOOOOOOZOZOZO=.......
............,::,.......,OO7:................,+$OOZOZOOZOZZOZOZZOOZOZOZOO=.......
...........~$8OI........$OOZI~,.........,:=IZOOZOZOZOZOOOZOZOZOOOZZZOZOO=.......
...........:??=:.......:OOOOOZZ7+=~~==+?$ZOOOOZOOOZOZOZOOZOZOZZOZZOZOZZO=.......
............::,.......,+OOZOOOOO$7777$$ZOOOOOZOZZZZOZOZZZOOZOZZOOOZOOZOO=.......
.....................=7OOZOOZOOZOOOOOOOOOZZZOZOZZOZOZOZOOOZOZOZZOZOOZOOO=.......
................,:=I$OOOZZOOOZOOOOOZOZOZZZZZOOZZZOZOZZZOOZOOZOZOZOZOZOOZ=.......
...........:~+?7ZOOOOOOZZZOZOOZOZOOZOZOZZOZZOZOZZZZOZOZZOZOZOZZOZOOZOOOZ=.......
........$$ZOOOOOOOOZOZOZZZZOZOZOOOZZZOZZZOZOOZOZZZZZZZZOOOZOOZZZOZOOZOOZ=.......
.......~OOZOOZZOOZZZZZZOOZOZOZOZZOOZOOZZZOZZOZOZZOZZZOZOOOOOZOZOZOOZOOOZ=.......
.......~OOZOOZZOZZOZOZZOZZOZOOZOZOOZOZOZZOZOOZOZZOZOZOZOZOOZOZOOOZOOZOZO=.......
.......~OOZZZOZOOOZOZOZZOZOZOZOZOOZOOZOOOOZOZOOZOOOZOOOZOZZOZOZOOZZOOOOZ=.......
.......~OOZZOZOZZZOOZOOZOZOZOZZOZZZZOZZZZOZOZZOOOOZ$ZZZZZZOZZZOZZOZOZZZO=.......
.......~OOZZOO$??$OOZOOZZOOZOZOZ+~IZOOOZOZOOZZOOZI==IZOZZOZOOZOZZOZI~=7O=.......
.......~OOZO$I:..~IZZZOZOZOZOZ$+...=7ZOOZOOZZOZZ=,..,=$ZZOZZZZZOZI~...,?=.......
.......~OOOZI:....:IZOOOZZOOO$+:....~7ZOZOZOZOZ$,....,=$OOZOOOZOI~.....:~.......
.......~OZI~........~IZZZOZ$?:........=IOOZZZ$+,.......,$ZOOOZZ7................
.......=7~............~IOZI:............7ZO$+:..........,=7ZZ7=,................
.......,,...............=~...............~=:..............,~=...................
GlassGiant.com"""
print "Hello World!"
很久以前,我遇到了一些连接脚本,虽然我不记得语法,但我记得那些评论,因为我是 Pink Floyd 的粉丝。
//Attempt Handshake: Hello? This is London calling. Are we reaching you?
//Handshake Failed: I don't understand...he just hung up.
一个可怕的解码补丁(意大利语翻译):
/**
*@return the value
*@param key: the id of the list of instruments
*@PS this function is a violation of all the laws of the
*software engineering,
*commons sense, highway code
*and ONU decision about the coding.
That sh*t...
*/
那是众所周知的,但我喜欢它(在 sys/ufs/ufs_vnops.c 中):
/*
* A virgin directory (no blushing please).
*/
在 FreeBSD 内核源代码树中(甚至更早,回到 4.xBSD)
/**
* As Gregor Samsa awoke one morning from uneasy dreams he found himself
* transformed in his bed into a gigantic insect. He was lying on his hard,
* as it were armour plated, back, and if he lifted his head a little he
* could see his big, brown belly divided into stiff, arched segments, on
* top of which the bed quilt could hardly keep in position and was about
* to slide off completely. His numerous legs, which were pitifully thin
* compared to the rest of his bulk, waved helplessly before his eyes.
* "What has happened to me?", he thought. It was no dream....
*/
protected static String DEFAULT_TRANSLET_NAME = "GregorSamsa";
//Iterate by one
$i++;
不幸的是,在我的“必须评论一切阶段”期间,这是我的。
在一些网站上工作时,我在嵌入式 JS 的开头发现了这一点:
我觉得这样做很肮脏,但那个人想要在 .NET 中使用它
来自 C#
#region Hack - Shield Eyes Before Expanding
/// <summary>
/// A single uint with all of the bits set to represent the different tracing
/// </summary>
/// <remarks>
/// Ugly I know, so if you can think of a better way, feel free to rewrite.
/// </remarks>
[Browsable(false)]
public uint TraceBitfield
{
// Snip
}
#endregion
来自英国银行申请中的承包商。
// i don't know how this works but it does so i'll leave it here anyway
他还添加了 BNP(英国极右翼政党)作为测试的虚拟客户之一……我们的直接上司是亚裔。
我没有要分享的代码,但想象一下这种情况。在我们的 Linux 系统管理员前往更绿色的牧场大约一两个月后,我有幸打开了他编写的 shell 脚本。我不记得为什么我需要编辑它,但这并不重要。重要的是脚本大约有 40 行长。我滚动了评论(其中有 37 行)以到达实际的工作代码(3 行)。代码很棒,但我很好奇——为什么要 37 行注释?所以,我滚动到顶部并继续阅读。令我惊讶的是,评论是关于三行代码的作用以及如何更改它的说唱。最好的部分 - 这是 Dr. Dre 和 Snoop DO DOUBLE G 对 Nothing But AG Thing 的部分抄袭。谢谢 Brian!
/*
* TODO: Remove this function
function remove($customer_id)
{
$this->Customer->remove($id);
}
*/
catch
{
// you’re fucked
// write out the file somewhere and start screaming “Connection down! Connection down!”
}
//Time log says you've been here for 15 hours GO HOME, your code is hobo
// woot, global var. I havent done this for a long time.
public static final void attachListener(Object listener) {
/* ======================= */
// This does nothing, continue searching
/* ======================= */
...
让听众痛苦!
// but the "real" solution is much more complicated
来自 jpgraph
我看过一次:
//this used to be a comment
// HACK ! COPY/PASTE this and look for another job
注意上述代码中的错误;我只是证明它是正确的,没有尝试过。
那是唐纳德·克努斯(Donald Knuth)的作品。
//too much log will kill you
这条评论是我自己写的,当时降低了一些日志的优先级,否则这些日志会写入数百 MB 的垃圾并严重削弱应用程序的性能。
at the end of a rather long and convoluted set of while loops and if blocks, the developer in question inserted this final comment:
else
{
// wobbly wilson said this would *never* happen!!
}
a laconic mixture of wit and sarcasm :)
这对其他人来说很有趣,但对我来说却不那么有趣。我从自己继承的开发人员那里继承了代码(即 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 代码。
...是客户向我强调了评论。
:-(
' Oh man I'm pissed. I think I better go home.
哪里生气 = 喝醉了
//FIXME: fix this before the 1.0 release
他们在第 4 版
从旧的 Perl CGI 脚本:
# This is convoluted and evil, sorry.
#!/usr/bin/sh
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All Rights Reserved
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#ident "@(#)false.sh 1.6 93/01/11 SMI" /* SVr4.0 1.3 */
exit 255
取自 SunOS 5.9 aka Solaris 9 (/usr/bin/false)
看到这个:
'On Error Goto Hell.
/* logic */
#ifndef TRUE
# define TRUE 1
#endif /* TRUE */
#ifndef FALSE
# define FALSE 0
#endif /* FALSE */
#define EOF_OK TRUE
#define EOF_NOT_OK FALSE
以及其他精彩的mkenentry.c在IOCCC页面上。每次阅读此来源时,我都无法继续大笑。
// 在这里设置断点 - 你永远不会到达它
//Not a bug, parameter position can change..., if you think this is wrong, you are in fact wrong.
伯克利数据库
/*
* Chaos reigns within.
* Reflect, repent, and reboot.
* Order shall return.
*/
return (DB_RUNRECOVERY);
我没有直接遇到这个,但它是一个很好的故事(见我评论中的解释):
#define MSGTAG_B33R 0x723 /* RIPLVB */
/*
* After 36 hours, 2 holes in my wall and writing my code right beside the API
* this still doesn't work.
* function getMap():void takes in an event object @param: evt:mouseEvent
* I will now retire for the day with a bottle of rum and 2 hours of crying
*/
直到最近,我一直在从事一个非常可爱的项目(是的,我承认,其中一些是我的,但我不会告诉你是哪一个):
if(FAILED(hr))
{
char fuck[256];
sprintf(fuck, "GetBuffer() fucking fucked the fuck: %d", hr);
MessageBoxA(0, fuck, fuck, MB_OK | MB_ICONERROR);
return;
}
// This is for Chris, since he gets all hot and horny over "uint" instead of "unsigned int"
// ... or maybe he's just a lazy fuck. Who knows!?
using Ogre::uint;
// movable texts, fucktory
MovableObjectTextFactory* m_pMovableObjectTextFactory;
// diarrhea... shitting CR from the string. complete run...
他的意思是他用回车符分割字符串以分别渲染。
// unlock shit (duh, this comment is useless)
pixelBuffer->unlock();
// :HACK: remove me after demo is shipped
Of course, it's still in there ;)
// it's 4am and I can't think of a decent error message.
// my lead just fell asleep at his desk, so I can't ask him.
// [name] went home because he didn't want to get divorced.
// and so it's little ol' me, sitting here, comin up with an
// error message for something that should never ever happen.
ASSERT0(in_len == max_in, "http://www.youtube.com/watch?v=oHg5SJYRHA0");
// you want hungarian, you GET hungarian!
for(int fcknglpidxcntvrI = 0; fcknglpidxcntvrI < len; fcknglpidxcntvrI++)
bool bKillSomethingAlive = false; // beating the dead horse instead
当然,我们也有很多有趣的方式来表达“Hack”:
// HACKOMATIC
// HMM... HACKXOR?
// HACK'O'ROONY
// AR; yeah I know it's HACKsoup
// HACK SHOT! DOMINATING!
// HACK'KIDO
// HACKku. sepukku. harakiri. kamikaze. ninja.
// HACK'o'NEIL
// HACKsaw
var something TBoolean; //Pickins
What do you think you're doing, Dave?
// All this code is yours, except gedit()...attempt no modifications there.
/* Only break the connection if it actually exists. It is important to
* check the timeslot saved in the SOURCE of the disconnect message. */
我写了这个评论,现在我不记得为什么它很重要......
BEGIN.
// Here might be dragons
.
.
IF...
// Beware of the Jabberwocky
.//user the force, luke
.
.
ENDIF.
.
END.
private static final Logger lager = new Logger();
/*
* Wirzenius wrote this portably, Torvalds fucked it up :-)
*/
If you have reached this part in the code, then this program sucks.
// this is really complicated
没有其他评论
# let's pretend we are free, for a while
在一堂课前发现了这个。接下来是(天真的)尝试实现 ORM。我还是不明白他为什么写这个。
//ha, you thought I was lazy didnt ya?!
几年前,我在一个没有单元测试可言的大型代码库中工作。
代码深处有一种方法可以执行一些日历计算。它有点坏了,由于一些不幸的情况,不得不以一种非常笨拙的方式处理夏令时。
我们不得不修复它几次,每次,我们都会在几个月后发现有什么东西坏了。
在花了一整天的时间修复它并分析它之后,我将代码放入源代码管理中,并附上这样的评论:
// this code was written after a version trying to do {this} failed because of {reason},
// previously we were doing {this} which failed because of {reason}. This is
// now written {this} way so that {lots of reasons here}. If you want to touch
// this code, please make sure that it produces the right answers when tested with:
//
// {some sort of unit test}
最终,我的团队被外包了。有时候我想知道这段代码发生了什么:)
//If the Current Record is Getting End Dated, We should not create New History Entry.
//We Just need to Update the Previous History Entry
//If the History is already End Dated and the New Record is now removing End Date, Then
//We should not update the Previous History End Date.
//We Just need to Create the New History Record Only.
//Alright..
//Alright....
//Enough Comments. Code it. :-)
#define SHIT_HAPPENED (BASE + 1) /* generic shit happened */
// The freshest corpse at the back please.
m_DeadCharacters.push_back( std::make_pair(character, 0.0f) );
// Get rid of the rotting surplus
while( m_DeadCharacters.size() > 3 )
m_DeadCharacters.pop_front();
这是我们在前雇主购买的智能卡产品中发现的唯一评论。一堆由荷兰密码学博士编写的嵌入式 C 和汇编程序
// echt halmaal gek - no way!
(这意味着像“真的完全愚蠢”......这也没有帮助我们)
javascript函数的第一行:
// this part is more difficult
怎么回事?
Found in the main trigger code for transactions in an OLTP database:
-- This line negates the @inverseqty, which is the
-- negative of the @insertedquantity. This works through the
-- magic of the trigger. In fact, this code is a lot like
-- the bermuda triangle!
@negquantity = -1 * @inverseqty
//marco 2007.1.23
//I didn't do it
#define FUCK_VS6_CANT_COMPILE_TEMPLATES_WITHOUT_HANDHOLDING ((float*)0)
...
SetPinsFromChannels`<float`>(&pinbuf, streambuf, &inmapper, FUCK_VS6_CANT_COMPILE_TEMPLATES_WITHOUT_HANDHOLDING);
严格来说,这不是评论,但...
那是 1990 年代中期,我正在进行大规模迁移:小型软件供应商、大客户、巨大压力。我们有很多移动球门柱的东西。这个项目很难控制。我是主要开发人员,但对系统不熟悉,另一位开发人员是供应商的所有者/创始人。
在几个月没有完全确定最后期限并且不太让客户满意之后,所有者/创始人聘请了另一位远程工作的开发人员。(我会冒昧地说新开发人员的技能和经验比我少。)
好吧,新人对我已经处理过的代码进行了一些更改,然后一两个月后,我又回到了代码的同一区域,并且出现了我以前从未见过的变量。像StupidMark
.
伙计,那是不对的。我的意思是,有团队合作的考虑,而且:在这种环境中,变量名可以显示在运行时错误消息中。我只是说。
在我当时看来,新人的代码并没有让我们更接近可交付的产品,这让侮辱更加刺痛了。
就在今晚,我们的团队发布了一个新版本的 CSS 文件,该文件从一个结构如下的文件中删除了注释:
@charset "UTF-8";
/* Who knew comments here could COMPLETELY ruin our page in Safari? */
body {
/* Really important stuff here */
/* Of course, comment or not, this will all get ignored by Safari because
its the first rule after the comments which break everything.
see http://www.w3.org/International/questions/qa-css-charset for the exact details!
*/
}
有趣的是在网上你会发现人们的解决方案是输入一个虚假元素作为字符集语句下方的第一条规则,以被忽略并正常进行......
深思:一个人把评论放在哪里不评论?
旁注:由于标题、元规则等,我知道这不应该是必需的。不幸的是,我们需要它作为一个包罗万象的:(
try
{
...
}
catch(Exception ex)
{
//if this happens the world is going to end...
}
现在猜猜发生了什么……
On error resume next 'because nothing will ever go wrong!
我刚刚在 .net 的自定义 Linq 提供程序中找到了这个:
//select is a royal pain in the ass where
//the parameter passed to CreateQuery isn't actually the one that goes in the call
//requiring this workaround. Not sure how straight Linq to Objects does it.
和这个
//expressions have to be compiled in order to work with the method call on
//straight Enumerable somehow, LINQ to objects itself magically does this.
//Reflector shows a mess, so I (Aaron) invented my own way. God love unit tests!
我也发现了这个……它变得更好了
//ok, this is a hairy, dirty, and nasty piece of code
//the alternatives are substantially worse than this though
//i.e. when you do your own provider, LINQ assumes that
//you are going to implement your own expression tree visitor and
//do it all yourself. Frankly, I still have xmas shopping to do
//and I really don't want us to be foobared when we get
//even more extension methods added to LINQ
//therefore, we are pulling execute based on taking the calling the
//standard execute on enumerable, but using our own class
//
//optimization can occur from here on an as needed basis, that is
//check for the value of mex.Method.Name, and write a handler for
//that method
//
//also, it may not be a bad idea to rather than do this reflection
//each and every time somehow cache the reflected methodinfos and do
//lookups that way that said, we need a complete red/green/refactor
//cycle here before I am touching that one
和这个
//Compile that mutherf-ker, invoke it, and get the resulting hash
// good luck!
Something I saw in a .h file years ago.
// It may be a hack, but it works.
Something I saw in a COBOL program that paralyzed me with fear
* All comments pertain to the lines which follow.
What does this mean?
Someone was so uncomfortable with commenting that they had to write a meta-comment?
Someone was in the habit of putting comments below the relevant code and had been told to put comments above? How did that happen?
对于一个项目,我们将 pwlib 作为依赖项,当时它的 FreeBSD 端口有点搞砸了,所以我不得不从源代码手动构建它。它没有立即解决,我不得不查看代码;有一些复杂的类层次结构,其中部分代码由宏生成,其父类声明以
// The root of all evil ... umm classes
对于我编写的 memcache 包装器/处理程序接口模式类,我实现了以下方法。
/**
* Do not use, ever - left in place for testing purposes
*/
function I_David_WillHuntYouDownAndHurtYou_Badly_IfIFindThisUsedAnyWhereInTheAppLibrary(){
...
}
这基本上是一个超级核函数,告诉所有单独的内存缓存服务完全刷新自己,并从我用于键的各个名称空间计数器开始(例如 .{_counter_key value}_.{_counter_key value} )
我写的另一篇小中篇小说是为一个数据供应商的自动下载器,详细描述了我是多么讨厌这个供应商,并竭尽全力假设他们的基础设施的批处理系统是由沙鼠运行的,在轮子上运行,经过这么多的革命轮子将启动下一个排队的任务。它是在 6 个月的时间里编写的,添加了额外的异常处理,像(如果我们有 768 字节的 \s 字符,这意味着对其数据库的查询超时,空格是空失败打印语句的结果。
// Empty constructor to satisfy the stupid compiler
Public ServletHandlerClass () { }
int main(void)
/* Program starts here */
// haack, phil haack
和:
/* hack, hack, hack, hack, hack hack, hack, hack
* hackity hack, oh wonderful hacks
* wonderful hacks, oh wonderful hack, hack, hack
* hack hack hack... and spam
*/
编辑:刚刚在我的一些代码中发现了这个(该项目希望保持匿名):
// yikes, we need to:
/*
* o
* -|- < US CROSSING PLATFORM
* |\
************************************************
* | ^ PLATFORM |
* | T |
* | TROLL^ |
*/
// right now:
/*
* o ./_ |
* -|-[]\ | (_'_) () (\) | ) \|/ (S) < WALL
* |\ | ^ FRIENDLY MESSAGE FROM YOUR FRIENDS AT MICROSOFT
* ***********************************************
* | ^PLATFORM |
* ^ SPRAY CAN (IN HAND)
*/
public static class DefaultFonts
{
public static string SansSerifPath
{
get { return @"C:\Windows\Fonts\arial.ttf"; }
}
public static string SerifPath
{
get { return @"C:\Windows\Fonts\times.ttf"; }
}
public static string MonospacePath
{
get { return @"C:\Windows\Fonts\courier.ttf"; }
}
}
我多么喜欢双关语。
//If only humans could leave things be.
//Please do not edit this code,
//if you do you wont go to jail, you wont go directly to jail,
//you wont pass go, you wont collect 200 dollars
当我在一个我被要求维护的项目中读到这篇文章时,我哭了。
//Write Code Here
我仍然畏缩:)
// Iced odnako
bool Iced{get;set;}
switch(value)
{
[...]
default:
ASSERT(**true**); // if this is triggered, something really bad is happening.
}
def leppard
# what, i cant have my own convention?
end
从 sendmail 配置文件。经过一页又一页的看起来像是简单的线路噪音。我找到了这颗宝石。
# insert this handy debugging line wherever you have problems
#R$* $:$>99$1
-- Beyond this point, there'll be dragons
I find it more pleasingly illustrative with the longer saying ^^
//Please comment on your source code
在我们用于政府目的的企业级系统中发表评论
'RH 5/24/06 burn me if this dosn't work.. :)
Good ole RH.....company Prez/Lead Developer
在 1983 年的一些 COBOL 中看到:
C I don't know what this next bit does so I'll jump around it
GOTO DONE.
Best comment I ever saw was
/*
There is no accounting for pointers
*/
Get This hack!
在一行汇编代码上,在几页未注释的代码之后。
我刚刚完成了一个日志框架(它使用 Trace,我不知道为什么不存在这样的东西)。我创建了一个继承自 TraceListener 的便利基类。它覆盖了所有 TraceListener 方法并将它们路由到一个方法中 - 所以这是很多文档评论:
// TODO: Need some codemonkey to doc comment this class.
/*
FIXME: why the fuck did anyone ever think this kind of expensive iteration
was a good idea?
来自 Python/ceval.c:
/* This is gonna seem *real weird*, but if you put some other code between
PyEval_EvalFrame() and PyEval_EvalCodeEx() you will need to adjust
the test in the if statements in Misc/gdbinit (pystack and pystackv). */
这是我今天在重构一些代码时发现的评论
if( year < 100 ): year += 2000 #lol, Y2K
在 SJ CA 的拍卖业务早期,我与一个名叫 Rick Dorin 的人一起工作。当你不得不整天戳卡片时,他会写回编译器。他的错误信息之一是
错误太多...减少!
// for 8 or 12 threads this does not affect much.
// Strange are the situations if not understood properly.
// Yoda strikes again
在多线程模块中!:)
Back around the time the Hitchhiker's Guide game was new, I had a case where I was testing whether something was scrollable and whether the user was trying to scroll, in a language that restricted variable length. So:
if (scroll and noScroll) # or tea and no tea
private int mousycounter = 0; //Not really a counter
//Do not continue reading if you dont want to die.
这个差点要了我的命。
// simply copied from another code
我的热门歌曲汇编:
// Thats the end of the While loop
// Clean up last row. I really must program better than this.
// Note: You can't immediately tell if the line below works.
// Rounding - blech. It's assumed that all .5s are rounded up.
// Sort out predictions first. Seems like the right place for a prediction, 'first'.
// Let's interpret!
在一些非常糟糕的 vb 代码中(我知道这很糟糕,但是)我在一个空的 if 控制块中发现了一个注释,上面写着:
If bFound Then
'I love it when I write kick ass code like this
Else
.
.
来自 Joomla!资源:
// this is daggy??
Gosling 的 Emacs源码中的 ascii-art 骷髅和交叉骨(这里很难重新创建)(警告他写的超热屏幕管理包不容易理解)。
I just checked this in the other day...
/// <STERNLY-WORDED-WARNING>
/// Pay attention to this or I will hunt you down.
/// ...
/// </STERNLY-WORDED-WARNING>
Where ("..." == "proprietary stuff that I can't post"). I just liked my STERNLY-WORDED-WARNING element.
// Jay knows what's going on here, but will he remember in a year? Not very likely, this code sucks, but it works so do not change it.
此评论发布在一个巨大的 while-if-for 块上方......哦,它操纵了一个对象数组的对象数组的对象数组的对象数组的字符串或数字,这取决于至少 3 个因素......(是的,我不得不调试这段代码并更改它,我写了评论,但是我没有写原始代码)。;)
//下面的代码需要注释掉。
在 PeopleSoft Financials PeopleCode 的早期版本中:
/* I don't know how you can ever get here so I'll have to fix it later */
一旦我发现这个:
// I wish (boss name) could do this by him self.
Dennis M Ritchie 在这里有一个关于一些古代 UNIX 评论的页面
/*************************** Drag And Drop Section - Start (you should be me to mess with this section)*********************************************/
来自旧的 netscape Mozilla 代码的经典之作。我个人喜欢
就是不能乱搞。哦,无论如何,移动记忆也会毁灭我们,而且这一切都太他妈难以弄清楚了。所以,我放弃了,Mac 完全是一团糟
但还有很多其他有趣的。
回到大学:
//why the f*** we have to move this here to make it work
当我们与教授一起复习时,它在印刷资料中被突出显示。
原因:一些与缓冲区溢出相关的非常讨厌的错误,它影响了与代码其他位置的文件处理程序无关的变量。移动变量将使其再次工作。
// No women, no children... What movie???
刚刚在一些我必须更新的 Actionscript 中发现了这个...
/*
* spaghetty code in this module.
* hardcoded variables for load paths for the content window.
* Needs (vast) improvement.
*/
..伟大的 :(
// Keep prozac ready if things get ugly!
'""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'
' NOTE: DON'T SCREW WITH THIS CODE UNLESS YOU REALLY UNDERSTAND IT!
'
'""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
// The hackiest hack that ever did hack
它在WordPress博客引擎中(wp-admin/includes/user.php - 如果有人真的想看看这个 hacky hack 本身)。
// barcore.cpp - MFC
//.....
HBRUSH CControlBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
LRESULT lResult;
if (pWnd->SendChildNotifyLastMsg(&lResult))
return (HBRUSH)lResult; // eat it
//......
// Eat it - just like eat this.
在一个艺术资产导出工具中,我偶然发现了一个从数字(阿拉伯)数字到罗马数字的完整翻译器。它看起来像这样:
/*
//You can tell I was bored
//I wanted to do this for a long time
char* ConvertToRoman(int number, int base)
{
... whole code here
}
*/
编写这段代码的团队已经工作了很长时间,我猜这影响了他们的理智。
/* Jeez, this is an ugly mess */
...comment from the X11R6 internals source code circa 1991.
DataRow[] foundrows = FilterCalendarEntriesBecauseDotNETIsFuckedUp(tbtemp,CalDate);
不是评论,而是一个有趣的函数名
我找到了这个
// This is a kind of magic...
我经常发现这个
// fix it!
// TODO: Delete
在使用 Paradox 3.5 编写的大型预算系统工作多年后,我曾经接到客户的电话 -
“我们在调试时遇到了一些评论”-
// This shouldn't happen, if it does, then the bits that automagically
// worked when I wrote it have stopped working
……!
'Major changes: Everthing! - Removed all Cornoud's code !
发现了一个复杂的代码 -
//耶稣和这段代码有一个共同点:都复活了
// if the resultMap size is less than or equal to zero
// then the product is added
if (resultMap.size() <= 0)
%%return_median
hit_the_sweet_spot(Arg)->
.
.
// now that's compact!
list->insert(list->end(),**pitch)->IdxOfSample=(pitch->pos-Offset)*SamplingRate;
'I hate nested regions and will delete them along with any code found in them.
在 Python 的模拟教程中可以看到以下代码。
# This is my rifle.
def rifle(type='hunting'):
print('This is my (%s) rifle.' % type)
# This is my gun.
def gun(type='hand'):
print('This is my (%s) gun.' % type)
# This is for fighting.
def fighting(type='illegal'):
print('This is for (%s) fighting.' % type)
# This is for fun.
def fun(type='gaming'):
print('This is for (%s) fun.' % type)
作者一定是全家福的粉丝。^_^
// The following array may contain either TexturedObjects or ColoredObjects.
// I know, it sucks.
从 Linux 内核源代码:
linux/include/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
*/
double t = 0.0; /* that's generally my opinion of the diner, too. */
// Sorry dirty code
我曾经使用 MS SQL Server Developer 2000(人工工作流的东西)实现了一些文档工作流。
它由一堆触发器组成,这些触发器将被添加到数据库中以使其遵循工作流规则。
在其中一个触发器中,微软的某个人写了一些类似的东西:
//Determine if the database has been "Grizzlified"
(产品的内部名称是“Grizzly”,所以我觉得这很有趣)。
$dnstime = time() + 60 * 60 * 24 * 7 * 2; //how long are you staying for vacation on mars? twooo weeeeeks. give dees people air
// GK Experimental
(GK 是 coder 的首字母)
用于表示确实是实验性的代码部分。:)
一个很好的标志,知道当你在调试过程中点击它时,你可能会在接下来的几个小时内忙于修复黑客.. ;)
我从事的一个大型项目在自动构建中使用了 StyleCop 和 FXCop,并使用规则来防止人们签入带有未注释字段、方法、属性等的代码。
有人对必须将诸如“获取或设置全名”之类的注释添加到诸如FullName之类的自文档属性而感到非常生气,以至于他们努力编写宏来绕过规则。
该宏为方法、属性等插入了 XML 摘要标签,其中包含一个不显示的 Unicode 字符作为标签内容,这将愚弄构建规则,同时对他为了评论而盲目坚持评论内容进行了轻微的打击......
...至少在他们引入另一条规则来检查评论中的 Unicode 字符之前。
在生成 HTML 的旧 perl 脚本中找到:
# I would be _very_ brain farting if I said this code didn't need reviewing.
# It will make babies cry, and hair grow on your back, so please don't use it
从/System/Library/Frameworks/AppKit.framework/Versions/C/Headers/NSTextView.h:
- (void)smartInsertForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace beforeString:(NSString **)beforeString afterString:(NSString **)afterString;
- (NSString *)smartInsertBeforeStringForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace;
- (NSString *)smartInsertAfterStringForString:(NSString *)pasteString replacingRange:(NSRange)charRangeToReplace;
/* Java note: The second and third methods are the primitives and are the
methods exposed in Java. The first method calls the other two. All
Objective-C code calls the first method. In either Objective-C or Java any
overriding should be done for the second and third methods, not the first
method. This will all work out correctly with the exception of existing code
that overrides the first method. Existing subclasses that do this will not
have their implementations available to Java developers. Isn't Java wonderful? */
else
{
//error situation
}
来自http://www.madore.org/~david/computers/callcc.html:
/* Yow! DEMONS are flying through my NOSE! */
Fix problem where Nulls don't work properly. Stupid Microsoft!
代码以迂回的方式逐行将 Null 转换为零长度字符串,因为愚蠢的程序员不了解 Null 是什么,也从未听说过 Nz() 函数。
try {
dataSource.close();
}
catch (SQLException ex) {
// Do nothing, since we're going to trash this anyway
}
当然,这种事情实际上是 JDBC(或至少是 Oracle 的 JDBC 驱动程序)中的一个 wtf,因为它可以在关闭连接时抛出 SQLExceptions ......
单元顶部附近:
// Oh what a tangled web we weave
// When first we practice to deceive
// ASTA
今天早上我遇到的 VB.NET 中的一个不错的,笑了...
''' <summary>
''' Represents an exception that was logged. Since System.Exception implements IDictionary, it can't be
''' serialized, so I had to write this. Pretty fucking stupid thing to have to do, System.Exception should
''' be serializable right out of the box, IMHO.
''' </summary>
''' <remarks></remarks>
Public Class LogException
I've just placed this comment:
// this control (Resistance) is FUTILE!
'this next if statement - just how it is. don't try to understand it because you won't. :)
这就是工作保障。
在 eMule 的 Preferences.cpp 中,强制最小上传速度限制与您的下载速度限制成正比:
uint16 CPreferences::GetMaxDownload(){
//dont be a Lam3r :)
uint16 maxup=(GetMaxUpload()==UNLIMITED)?GetMaxGraphUploadRate():GetMaxUpload();
if( maxup < 4 )
return (( (maxup < 10) && (maxup*3 < prefs->maxdownload) )? maxup*3 : prefs->maxdownload);
return (( (maxup < 10) && (maxup*4 < prefs->maxdownload) )? maxup*4 : prefs->maxdownload);
}
这是我在不同时间放入代码中的一些内容。有些不是技术上的评论,但它们是同一种概念。
在一个跨平台项目中,只需要一个平台上的一些特殊代码:
//If defined, will include all the Windows-specific code.
#define LOSE
#ifdef LOSE
#include <windows.h> //WIN32. Duh.
#endif
---------------------------------------------------
//Stolen from other_project_name.cpp
---------------------------------------------------
/*
* These comments have been lifted from propagate() and, though they no longer apply to the code, they may still be of value somewhere. Original tabbing and structural elements have been preserved.
*/
//CAUTION: This has a major Bobby Tables risk. Even if a rulebuilder is used, there's still the risk of something getting corrupted in the database itself.
//Reading text from anywhere and simply slotting it into an SQL statement is a major security risk. (With thanks to xkcd for the name "Bobby Tables".)
//Requirement: Eliminate one Bobby Tables by changing [redacted] to be not just straight SQL.
[lots more comments that are not as funny]
/*
* End of lifted comments. There should not be any executable code between these markers.
*/
---------------------------------------------------
/*
Okay. It's unrecognized. Why is this a fatal error? It's actually very closely akin to the miswart of botched #includes being a fatal. When writing a C/C++
program, you need your headers, and if you don't have one, chances are there'll be a million cascaded errors; so by making "unable to open asdf.h" a fatal,
the compiler suppresses all those errors about undefined symbols and potentially misspelled type names.
*/
---------------------------------------------------
//If someone tries to import 'id' as a field name, it won't work. (We already have our own id.) But I think the probability is so low that I can afford to be funny.
if (!stricmp(ptr,"id")) {warn(0,"Import","","'id' is a reserved word and cannot be used as a column name. (Try 'ego' or 'superego'.)"); return;}
---------------------------------------------------
//Need a place to squirrel away SQL statements somewhere
char *uts[1024]; //Unified Temporary Storage. (Why? Because I said so.)
int nuts=0; //What is it that squirrels keep? Ha!
int utsid[sizeof uts/sizeof *uts];
---------------------------------------------------
/**************************************\
* NOTE: This sets tilde.action. If a *
* tilde header does not exist in the *
* import file (not the _content_, if *
* the entire column isn't there), it *
* will duplicate down through all of *
* the rows. This is fine for ~id, as *
* that will never be changed; and if *
* ~Quantity is blank, that throws an *
* error in 'Add'. With ~Action, I am *
* not so certain. I THINK it'd be OK *
* to dup-down most of the time... if *
* the user only ever imports Adds or *
* Revises, but never both at once in *
* a single import. So for safety, to *
* allow a blank ~Action to revise OR *
* add, I'm breaking the check out to *
* a new variable - the curaction. In *
* most cases, it won't be needed, so *
* it's a waste; but it isn't like it *
* has to copy the entire tilde.*, so *
* it's only a small waste. So it can *
* waste a register... big deal. OK ! *
\**************************************/
---------------------------------------------------
//if (!response) // we're going to crash
//if (!items) // we're going to crash
//TODO: Don't crash
---------------------------------------------------
我的很多评论都包含对电影或音乐剧的晦涩参考,但如果你不了解这个节目,它们就不会那么有趣了。
我没有源的副本,但我一直记得它:
// 如果你不明白,你不应该读这个
#pragma region Crap that is kept for temporary reasons
// Huge chunk of commented code
#pragma endregion
// Description : !!! TODO
来自 Joomla!资源:
// fudge the group stuff
我只是注意到自己在写这个
// not brilliant solution, but fair enough heh.
曾经有一位为我工作的程序员在他的代码中加入了“风格”注释,他在其中编纂了关于特定实现细节的内部辩论,并在他对特定编码决策被否决时采取了分镜。
例子:
'STYLE' 哪个更好是有争议的,但我传递图像句柄而不是简单地传递缩放值以保持调用代码更简单(通过一对声明语句)。或者,我可以直接从调用代码中传递这些数据成员,但这会违反封装。
'STYLE' 就像我在其他地方所做的那样,我将注册我的正式抗议(只需给我填写的表格)关于注释序列化的实现作为一个属性而不是一对加载/保存方法。再一次,这可能是一个“风格问题,非常值得商榷”。
消毒:
//Forward declarations:
class X {}; // TODO: Remove {} ! When we get X defined....
拉丁文,Abandon hope all ye who enter here
来自但丁的《神曲》。
最近在我们的代码中发现了这一点(我们开发企业软件):
// Instance of excel
Excel excel = this.CreateExcelInstance();
excel.Open(stream); // how to close it?!
在那之前,我确信我们已经摆脱了这些“有趣的东西”,而且我们正在以正确和意识形态正确的方式来做这件事……
我们有一个文件,其中一半的程序员试图理解混乱,设法将所有无意义的代码移到底部,并留下如下评论:
I have no idea what this stuff does below here.
另一位程序员留下了一系列嵌套的命名空间,这些命名空间的作用就像一本方向书,这样您就可以深入到想法中的命名空间并选择您的操作。
//Maybe you should make anyone knows your code's purpose.
这里有 4 个,不分先后:
// Father, forgive me, for I am sinning
// heaven help me
// horse string-length into correctitude
(from a textbook)
// what, me worry?
// repopulate, slight hax (or strong assumptions :P) below
当我注释掉我认为不再有用的代码块时,但我可能错了(因此不删除它们)我有时会在它们前面加上
// Wilted celery?
想法是这就像芹菜枯萎了,但无论如何你还是把它放回冰箱。我只知道10年后其他人会发现这些评论并说WTF?
if(count<0) count=0; //don't get me wrong but this has to be done :p
// StupidCompilerDontInline(SCDI), in the test project where
// allcode was in a single cpp the compiler had inlined nearly
// everything which lead to nice stackoverflow.
// To prevent this the metods are made virtual
#define SCDI virtual
我继承了一个在没有任何 UAT 的情况下交付给客户的项目。它被踢过栅栏和要求的钱。
第一次用,自然就炸了。它是一个插入库,它覆盖了任何将文件名作为参数而不是文件描述符的系统调用。
许多系统调用已被遗忘。
当我上船时,代码中充满了这样的宝石:
/* core dumps around here but this is hardly ever called */
和
/* don't know why this works but it seeems to be ok */
哦,没有单元测试。一位同事已经开始添加缺少的系统调用和单元测试。
而且写代码的混蛋还在团队里,根本不在乎已经送来的垃圾!
在 1980 年代初期的某个时候,我们正在为 PL/I 中的公用事业编写财务建模代码。接到客户的电话,评论后代码立即爆炸
/* Honest this works */
这家伙使用了我们的标准金融方程组,并做了大约 15 页的代数,将一堆代码组合成一个方程。在三英里岛之后,当公用事业公司不得不以巨额成本注销他们的核电站时,由于 FIXED BIN 15(整数)溢出,如果没有发生代数就不会发生这种等式失败。
在编写 MAPPER 应用程序时,我们有一些标准,其中之一是在整个套件中使用的标准变量列表。其中之一——“V43”总是用来表示姓氏。所以想象一下,当我被要求修复的一大段神秘的 MAPPER 代码中唯一的评论是:
Here V43 contains the Surname
/* Hammer Time! */
我不知道他在写代码时为什么或是否穿着防撕裂尼龙降落伞裤
TextBox1.Text = TextBox1.Text; //Point less yes, who writes this crap?
map(TimeZoneId.Romance, "Romance Standard Time"); //LULZ.
// This interface defines method signatures<br>
interface IWhatever { ... }
/* Look not upon this file lest your eyes be burnt from your head. */
我能说什么?我是实习生,暑假快结束了。容我们说,我对我的文件责任缺乏认真的承诺。
//this is a crap way to do this but I ran out of patience
DelButton.click();
/**
* Hexadecimal digit
*/
protected $version = -1;
// Holy moses! I've never seen anything so ridiculous in all my life.
// Why do we need to query the AlarmIDs table twice.
// Please tell me sir; I would really like to know.
// This like all the other services have been mangled
// to the point where they are nearly impossible to determine what kind of side affects might occur.
// I am making the smallest changes I can to this code.
// The GetAlarmId method gets the alarm id from the AlarmIDs table.
// Novel idea, why didn't we query for the values be get below all in the same place.
// This should be changed, but right now it will have to remain as is due to time constraints.
// This like all other services really don't do anything fantastically hard, but after the original coders got
// done with them; they are difficult to work with and have an acceptable comfort level.
首先在一个大对象的更新开始时:
/*General note to all who tread in the <ObjectName>() code...
* The SetOriginals() method from the BaseEntity class should be called (and only called) right after the Get() method
* call as seen above. Calling the SetOriginals method elsewhere will result in bugs and all kinds of other nasty suprises.
*/
然后经过大约 200 行逻辑来更新对象:
//Attempt to explain this confusing mess of code:
//First time you save an actual absence this is what happens:
//0. The first save saves to the <TableName> table (among other things). (Fig. A)
//1. The <CalculationMethod> method is called next which inserts to the <OtherTableName> table.
//(This is the table that keeps track of credits to the case.) (Fig. B)
//2. So then you have to call <UpdateCalculations> to move the <TableName> records to the <ThirdTableName> table. (Fig. C)
//3. Then you go back and run calculations since you have the debits table (<ThirdTableName>) populated. (Fig D.)
//4. Then a final save to save the calculations back to the case. (Fig. E)
//Yeah, I know what you're thinking: this sucks. 10/01/07 XXX
开发人员是对的……这太难了!
[vrk:Cloud ID="cTags" runat="server" DataTextField="Tag" DataWeightField="Total"
Width="100%" DataHrefField="Tag" DataHrefFormatString="~/tags.aspx?tag={0}"]
[/vrk:Cloud]
[!--if anybody would like to change the control's color contact with FLORJON--]
我真的几乎比评论更喜欢 oh_my_gawd 标签...
/* * IOC3 被操得令人难以置信......甚至不要给 * 通用 PCI 代码有机会真正查看它... */ if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 b_type0_cfg_dev[slot].f[fn].c[其中 ^ (4 - size)]; 如果(大小 == 1) res = get_dbe(*value, (u8 *) addr); 否则如果(大小 == 2) res = get_dbe(*value, (u16 *) addr); 别的 res = get_dbe(*value, (u32 *) addr); 返回资源?PCIBIOS_DEVICE_NOT_FOUND:PCIBIOS_SUCCESSFUL; oh_my_gawd: /* * IOC3 被操得令人难以置信......甚至不要给 * 通用 PCI 代码有机会查看错误的寄存器。 */ 如果((哪里> = 0x14 &&哪里= 0x48)){ *值 = 0; 返回 PCIBIOS_SUCCESSFUL; }
从技术上讲不是评论,而是在凌晨 2 点左右对某事进行编码:
consent = False
...该变量永远不会再次使用,并且出现在套接字的侦听循环的开头。
写得很好的 Lisp 是最容易阅读的语言之一,我喜欢它。但是写得不好的 Lisp 可能是一场噩梦,比糟糕的 Java 等糟糕得多。
在这里,如果存在以 a、b 和 c 后缀命名的原始文件的 3 个变体,我们需要创建一个“组文件”。我一直在试图找出一个奇怪的错误,我们得到了不必要的组文件......
(let ((varianta (format nil "~aa" problem))
(variantb (format nil "~ab" problem))
(variantc (format nil "~ac" problem)))
;;if the A and B variants exist, create a group file
;;(why not just check for a? I don't know, this just feels right)
(when (and (probe-file varianta)
(probe-file variantb))
...)))
错误:1,肠道:0。
显然,写这篇文章的人并没有想到检查所有三个变体可能是一个好主意。当然,这是我在最初编写这段代码十年后最终追踪到的错误(它早于第一个 SVN 日志)。
重新吃自己的狗粮:我们的工作场所有相同的术语(当然,只是因为我介绍了它)。我的代码中充斥着“TODO”的注释,并指出最终应该完成的事情,但是“DOGFOOD”的注释(两个关键字总是在注释的开头,全部大写)意味着必须完成的事情在这个程序甚至可以在内部使用之前。搜索起来很方便,因为“dogfood”这个词永远不会出现在带引号的字符串中——如果出现了,我总是可以说“dog-food”之类的——所以即使是不区分大小写的搜索也会出现得到正确的结果。
关于将累加器归零:在对 Intel 80x86 进行编程时,我做了完全相同的事情(我从 8086 开始,然后从那里升级到现代 Pentium)。将寄存器与自身进行异或是清除它的最快和最严格的方法。使用“MOV AX,0”需要三个字节(操作码和两个字节的文字 16 位零),而“XOR AX,AX”只有两个;对于 386 及更高的扩展寄存器,这一点更加明显,其中“MOV EAX,0”需要五个字节(四个字节的 32 位零)。我的 C/C++ 编译器总是以这种方式将寄存器归零,所以我认为它仍然是最好的方式(尽管我已经很久没有研究过操作码时序表了,并且可能 XOR reg,reg 和 MOV reg,imm 都需要一个时钟) .
// long live COM'n'Roll
public enum StatusCode
{
//success codes
S_OK = 1,
S_NONE = 2,
S_SQL_OPERATIONS_LISTS_EMPTY = 3,
//error codes
E_NO_MATCHING_END_FOUND = -1,
E_SEQUENCE_NUMBER_NOT_FOUND_AT_BEGINNING = -2,
E_SEQUENCE_NUMBER_NOT_FOUND_AT_END = -3,
E_FORWARD_AND_BACKWARD_OPS_COUNT_DO_NOT_MATCH = -4,
E_FORWARD_AND_BACKWARD_IDS_DO_NOT_MATCH = -5,
E_IDS_DO_NOT_MATCH = -6
}
// Hack-er-ama
我看到的一些旧的fortran代码:
integer *4 one,two,three;
c asssign one to 100 before entering the loop
one=100;
<cftry>
...code...
<cfcatch>
<!--- Gobble --->
</cfcatch>
<cftry>
It's all over my companies code base. It's ColdFusion and it simply ignores errors.
REM Don't delete this print statement ****** will die
有问题的过程是某些遗留代码中的服务
Mine fave was a variable name inside some of the business logic of a school project written in java.
int StupidJava = -1;
[onload_1;block=begin;when 1=0]
Some of the techinques in this template are rather obscure, just trust me, they need to be there.
OTOH a better sollution would be to create a few seperate templates and pick one in the php-script...
[onload_1;block=end]
(A bunch of code that's really weird looking) //Kludge.
这是来自一个旧的 IOCCC 获奖条目,我必须下载整个获奖者档案 - 一个巨大的 1.4 M - 并且在找到之前我记得错误的几个短语。
从语法上讲,这可能不是评论。或者可能是这样。我还没弄清楚。它绝对没有注释分隔符,但也没有字符串分隔符。
C="Lint says "argument Manual isn't used." What's that
mean?";
猜测 lint 的输出没有价格。
对于好奇的人,该条目就在这里。
// now swap like a <explicative removed>
// Oh crap, i think i'm gonna yack
紧随其后的是:
// TODO: end this lunacy
我刚刚在一些遗留代码中发现了这一点..
'CANNOT JUST QUIT!
我在 Access 中做一个数据库,非常简单的事情 - 至少它应该在一开始或者我会在 Delphi 中完成。客户希望能够从数据库中获取客户信息,但他们不会输入足够的信息来可靠地识别客户。我告诉他们使用电话号码作为密钥,因为每个客户(他们的工作方式,不是每个人)都有不同的号码。在他们打了几个疯狂的电话后,(它不起作用,我们无法输入客户)我发现他们懒得从他们的旧系统中查找电话号码,并试图输入他们不知道的所有号码“不适用”。在试图为他们解决这个问题时,我最终在代码中检查了很多循环,并在一个结果旁边添加了注释“
他们还问我一次“即使我们输入了错误的地址,我们如何才能找到合适的客户?” 一切都是为了花生。
回顾类的旧代码很有趣......
cardDeck.push_back(*(new card((rank)r, (suit)s))); // Push each card onto the deck
// Temp. objects are overrated
在经历一些事情时,这让我希望我在凌晨 4 点在破解随机代码时留下更多评论......