What is the best comment in source code you have ever encountered?
CommentsComments Problem Overview
What is the best comment in source code you have ever encountered?
Comments Solutions
Solution 1 - Comments
I am particularly guilty of this, embedding non-constructive comments, code poetry and little jokes into most of my projects (although I usually have enough sense to remove anything directly offensive before releasing the code). Here's one I'm particulary fond of, placed far, far down a poorly-designed 'God Object':
/**
* 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.
*/
I'M SORRY!!!! I just couldn't help myself.....!
And another, which I'll admit I haven't actually released into the wild, even though I am very tempted to do so in one of my less intuitive classes:
//
// 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
//
Solution 2 - Comments
Exception up = new Exception("Something is really wrong.");
throw up; //ha ha
Solution 3 - Comments
//When I wrote this, only God and I understood what I was doing
//Now, God only knows
Solution 4 - Comments
stop(); // Hammertime!
Solution 5 - Comments
This seems to stop morons from messing my code...
// Autogenerated, do not edit. All changes will be undone.
Solution 6 - Comments
// sometimes I believe compiler ignores all my comments
Solution 7 - 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.
Solution 8 - Comments
> //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
> {
> ///
> 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 > } >
> ///
> 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; > } > } > }
Update: The original author of the code has outed himself so I must give credit where it is due. Dan McKinley left the company I was with shortly after I started, and he talks more about the code, explaining some background and a few more "WTF's" that 'Richard' wrote.
Solution 9 - Comments
// somedev1 - 6/7/02 Adding temporary tracking of Login screen
// somedev2 - 5/22/07 Temporary my ass
Solution 10 - Comments
// drunk, fix later
Wish I were kidding. And knowing the developer who wrote the code, I think he meant it literally.
Solution 11 - Comments
// Magic. Do not touch.
Solution 12 - Comments
#define TRUE FALSE
//Happy debugging suckers
Solution 13 - Comments
// I'm sorry.
Solution 14 - Comments
return 1; # returns 1
Solution 15 - Comments
/* This is O(scary), but seems quick enough in practice. */
followed by four nested for-loops
Solution 16 - Comments
// Replaces with spaces the braces in cases where braces in places cause stasis
$str = str_replace(array("\{","\}")," ",$str);
Solution 17 - Comments
It speaks volumes about our profession that when asked about the "best comment", we all answer with the worst comments we can find...
Solution 18 - Comments
long john; // silver
Solution 19 - Comments
Catch (Exception e) {
//who cares?
}
Solution 20 - Comments
/**
* Always returns true.
*/
public boolean isAvailable() {
return false;
}
Never rely on a comment...
Solution 21 - Comments
/*
* 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.
*/
Solution 22 - Comments
try {
} finally { // should never happen
}
Solution 23 - Comments
From: 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.
Solution 24 - Comments
const int TEN=10; // As if the value of 10 will fluctuate...
Solution 25 - Comments
#Christmas tree initializer
toConnect = []
toRead = [ ]
toWrite = [ ]
primes = [ ]
responses = {}
remaining = {}
Solution 26 - Comments
About the middle of a 30 page xslt
<!-- Here be dragons -->
Solution 27 - Comments
long long ago; /* in a galaxy far far away */
Solution 28 - Comments
in a completely uncommented 2000 line method
{
{
while (.. ){
if (..){
}
for (.. ){
}
.... (just putting in the control flow here, imagine another few hundred ifs)
if(..) {
if(..) {
if(..) {
...
(another few hundred brackets)
}
}
} //endif
(I actually grepped out all the brackets one day just to see how bad it was, and, sans formatting, got this:
{{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{} {{{{}}{}{}{}{}}{{}{{}{}{}{}{}{}{{}{}}{}{}{{}{}{}{}{}{}{}{}{}{}{}{{}}}{{}{{}}{{{}}}{{}{}{}{}{}{}{}{{}}{}{{{}}{}{{}{}}{{{}}{}{}{}{}}{{}}}{}{{}{}{}{{}{{}}{}}{{}}}{{}}{{}}{{}}{}{{}}{{}}{{}}{{}{}{}}{}{}{{{}}{{}}}{}{}{}{}}{{{}{{}{}{}{{}{}{}{}{}{}}{}}{{}}{{}{}}}{{}}{{}}}{{}}{{}}{}{}{}{}{{}}{{}{}{}{}}}}{}{}}{{}{{{}{}{}{}}}}{{}{{{}}}}{{}{{{}{{}}{}{{}}{}{{}{}}{{}}{}{{}}}{{}}}}{{}{}{}{}{}{{{}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}{}{{}}{}}}{}}{{}}{{}{}}{{}{{}{{}}}}{{{}{{{}}}}}{{{{{}}}}}{}{}{}{{{{}}}{}{}}{{}{{}}}}
The endif showed up around line 800)
Solution 29 - Comments
//This code sucks, you know it and I know it.
//Move on and call me an idiot later.
Solution 30 - Comments
// If this comment is removed the program will blow up
Solution 31 - Comments
double penetration; // ouch
Solution 32 - Comments
/////////////////////////////////////// this is a well commented line
Solution 33 - Comments
// I don't know why I need this, but it stops the people being upside-down
x = -x;
Solution 34 - Comments
One of the most classic ones is the comment made by Pierre de Fermat about his well-known "Last theorem": "The margin of this page is a bit too small to write down the proof".
It took more than 350 years before the proof was found...
(According to wikipedia this is the original text:)
> Cubum autem in duos cubos, aut > quadratoquadratum in duos > quadratoquadratos, et generaliter > nullam in infinitum ultra quadratum > potestatem in duos eiusdem nominis fas > est dividere cuius rei demonstrationem > mirabilem sane detexi. Hanc marginis > exiguitas non caperet.
...and translated into English:
> (It is impossible to separate a cube > into two cubes, or a fourth power into > two fourth powers, or in general, any > power higher than the second into two > like powers. I have discovered a truly > marvellous proof of this, which this > margin is too narrow to contain.)
Solution 35 - Comments
// I am not sure if we need this, but too scared to delete.
Solution 36 - Comments
From Java 1.2 SwingUtilities:
doRun.run(); // ... "a doo run run".
Solution 37 - Comments
# To understand recursion, see the bottom of this file
At the bottom of the file:
# To understand recursion, see the top of this file
Solution 38 - Comments
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: <https://stackoverflow.com/questions/218123/what-was-the-strangest-coding-standard-rule-that-you-were-forced-to-follow#220101> ...
Solution 39 - Comments
I went through a sleep-deprived coding run and started only writing comments that were quotes from Fight Club.
Still trawling through the code years later I find a comment that makes me laugh. Most of them just random thoughts. I did however keep my comments to lines ratio pretty good!
// 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() {
Solution 40 - Comments
Many years ago (about 1994) I was working on a Oracle PRO*C application for a large multi-national software company that you will have heard of. The app I was working on was a massive Oracle application and they had a utility that ran overnight tidying up data and doing all sorts of aggregate calculations. Every time anything needed doing as a batch job, it got shoved into this utility and as you can imagine it became an absolute monstrosity. It was also notable for the tiny number of comments that it had for such a massive program.
One of the few comments it did have remains the finest comment I have ever seen for pure WTF'ness... I was trying to find a bug in a function which was hundreds of lines long and right in the middle of it was the only comment in the function:
/* I did this the other way */
To this day it is still the finest comment I have ever seen.
Solution 41 - Comments
/* Please work */
Solution 42 - Comments
//Dear future me. Please forgive me.
//I can't even begin to express how sorry I am.
And I just found this one today:
//private instance variable for storing age
public static int age;
Solution 43 - Comments
/* You are not meant to understand this */
Solution 44 - Comments
//I am not sure why this works but it fixes the problem.
This was before a set of code that technically did fix the problem it was meant to but broke 3 other things....
Solution 45 - Comments
// no comments for you
// it was hard to write
// so it should be hard to read
Solution 46 - Comments
/* Halley's comment */
Solution 47 - Comments
options.BatchSize = 300; //Madness? THIS IS SPARTA!
Solution 48 - Comments
// I have to find a better job
Solution 49 - Comments
Our DBA found this in the middle of a 3000 line stored procedure written by a third party.
/* IF DOLPHINS ARE SO SMART, HOW COME THEY LIVE IN IGLOOS? */
Solution 50 - Comments
on js code:
// hack for ie browser (assuming that ie is a browser)
Solution 51 - Comments
/* 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)
Solution 52 - Comments
... or die // bitch
Solution 53 - Comments
Try typing your favourite profanity into google code search, it whiles away many a dull hour. Some of my favourite examples:
/* 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. */
and my personal favourite
# code below replaces code above - any problems?
# yeah, it doesn't fucking work.
Solution 54 - Comments
On initialization of a linked list:
last = first; /* Biblical reference */
Succint and hilarious.
Solution 55 - Comments
Somebody complained that the "best" comment was bringing up the worst comments. IMHO, they're funnier, and so "better", but here's the honest best comment I've ever read:
/*
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).
*/
Solution 56 - Comments
if(m_measures =/*=*/ --index)
{
....
Solution 57 - Comments
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++ Comment
Solution 58 - Comments
/*
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
Solution 59 - Comments
mov si, pCard ; captain?
Solution 60 - Comments
// 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 */
}
Solution 61 - Comments
From the 2004 Windows leak,
__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);
}
Solution 62 - Comments
// this comment included for the benefit of anyone grepping for swearwords: shit.
Solution 63 - Comments
I saw this comment on someone's code:
// This comment is self explanatory.
I guess he meant to say 'variable' but the mistake made one funny comment... Think of the circular logic here, and the futility of writing it.
Solution 64 - Comments
} catch (PartInitException pie) {
// Mmm... pie
Solution 65 - Comments
Not quite a comment but a goto label
ICantBelieveImUsingAGoto:
Solution 66 - Comments
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!!!
}
Solution 67 - Comments
class Act //That's me!!!
{
}
Solution 68 - Comments
Next to a local variable that had to be declared just to pass a constant to a library function:
// This only exists because Scott doesn't know how to use const correctly
Solution 69 - Comments
virgin = 0; /* you're not a virgin anymore, sweety */
Solution 70 - Comments
public boolean isDirty() {
//Why do you always go out and
return dirty;
}
Solution 71 - Comments
* ...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...
Solution 72 - Comments
The original Doom had an engine with static walls that could not move; the result was that all doors opened vertically; nothing could ever move horizontally. I burst out laughing when, after the source code was released, I was looking through the code and saw this in the source file for handling doors, at the start of a big block of commented-out code:
// 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)
//
Solution 73 - Comments
Taken from the Quake III source, I stumbled across this in some random slashdot posting. Full source of the file can be found here"">http://www.google.com/codesearch?hl=en&q=quake+3+%22what+the+fuck%22+show:1s7s4Tr0knk:uJtln_6bKE0:1s7s4Tr0knk&sa=N&cd=2&ct=rc&cs_p=git://github.com/TTimo/iourt.git&cs_f=code/qcommon/q_math.c">here</a>;. It's a particularly fast method of calculating an inverse square root. As for the best comment? It's a common one to be sure, but given that it's attached to the line that does the magic is what makes it great.
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;
}
Solution 74 - Comments
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 .__ _.-\ \
## | | | ``/ /` /
## /,_| | /,_/ /
## /,_/ '`-'
##
Solution 75 - Comments
// 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.
And what do you think? The code below was safely ‘svn removed’.
Solution 76 - Comments
this has turned up in my own code a few times. obviously I touched it more than once:
// TODO: Fix this. Fix what?
Solution 77 - Comments
//MailBody builders for two outgoing messages
StringBuilder hanz = new StringBuilder();
StringBuilder franz = new StringBuilder();
I still chuckle a little when I read that one...
Solution 78 - Comments
Repeat
...
Until (JesusChristsReturn) ' Not sure
Solution 79 - Comments
on leaving my last job I embedded some ascii art into the source...
,-=(!7(7/zs.
.=' ' ./,/!(=)Zm. .._,,._.. ,-
-,\
--
\7//WW.
,v=/.-,-- -!|V-s.)iT-|s|-.'.//ct)8ZK%8///mK%. v!
i!-.e]-gbT/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@WZKYKZG5KMi,- vi[NZGM[
i!(44Y8K%8%%%**~YZYZ@%%%%%4KWZ/PKN)ZDZ7 c=//WZK%!
,\v\YtMZW8W%%f,
.t/bNZZK%%W%%ZXbK(K5DZ -c\/KM48
-|c5PbM4DDW%f v./c[tMY8W%PMW%D@KW)Gbf -/(=ZZKM8[
2(N8YXWK85@K -'c|K4/KKK%@ V%@@WD8e=)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!\-,-/i-v((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`
'''''
Solution 80 - Comments
/*
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;
Solution 81 - Comments
Don't recall where I've seen these:
long time; /* know C */
and (in code to create some sort of UNIX daemon):
/* Be a real daemon: fork myself and kill my parent */
Solution 82 - Comments
At the top of a header file:
/* 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.
*/
The "XYZ project" (name changed) was a seven-year ordeal. That last comment was written by the one stalwart soul who was involved from the very beginning through to the end.
Solution 83 - Comments
// Catching exceptions is for communists
Solution 84 - Comments
In drivers/net/sunhme.c (Linux kernel):
/* 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. */
Solution 85 - Comments
//
//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!
//
Solution 86 - Comments
/* 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.
*/
Solution 87 - Comments
A comment I added to a PHP CMS I was working on a while back.
if (/*you*/ $_GET['action']) { //celebrate
Solution 88 - Comments
Once I saw in another discussion something like this:
// I can't divide with zero, so I have to divide with something very similar
result = number / 0.00000000000001;
Clever solution, isn't it :) ? (It's a joke if someone's not sure)
Solution 89 - Comments
A classic case of why you shouldn't off shore your software development:
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; }
}
}
Solution 90 - Comments
in a homework assignment in college for a teacher who was particularly adamant that we comment our code:
//I wonder if she actually reads these.
When the assignment was returned, in red pen next to that comment "Yes, I do"
Solution 91 - Comments
Great one from leaked Windows 2000 source code :
> !!!!!!!IF YOU CHANGE TABS TO SPACES, YOU WILL BE KILLED!!!!!!! *
> !!!!!!!!!!!!!!DOING SO FUCKS THE BUILD
> PROCESS!!!!!!!!!!!!!!!! *
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Solution 92 - Comments
// 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.
Solution 93 - Comments
// 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
Solution 94 - Comments
// human madable inconvenient. Way too sucks.
I still don't fully understand what it means, but I have found it to be very true about a lot of code.
Solution 95 - Comments
// error codes
#define ERROR_SUCESS 0
#define ERROR_SUCCESS_IS_MISSPELLED 1
No other error codes defined.
Solution 96 - Comments
I always liked what Paul DiLascia wrote in his file headers:
// If this code works, it was written by Paul DiLascia. If not, I don't know
// who wrote it
Solution 97 - Comments
From a battery monitor module in an embedded system:
// batmon.c drives the rastamobile
Solution 98 - Comments
From the leaked Win2K source code:
// The magnitude of this hack compares favorably with that of the national debt.
Solution 99 - Comments
Another classic, by Donald Knuth no less:
Beware of bugs in the above code; I have only proved it correct, not tried it.
Solution 100 - Comments
//There can Only Be one HIGHLAN....err..Singleton
public class SomeSingleton
{
...
}