(Sorry, this post has gotten long. I realise now how many comments of mine are useless)
This is honestly something I submitted as part of a group (non-final) games project. 25 times a second, the update is called and this function is called as part of that. I considered taking out the comments that say "42% chance" because they make it too readable. (C++)
// Forecast: Sunny, with a chance of bad guys.
// But not too many bad guys.
void CGameApplication::randomSpawn(float timeValue)
staticint cooldownCounter; // minimum number of calls between spawns
if (cooldownCounter > 0)
// if no enemies, spawn one (for the hell of it)
if (m_hostileCount == 0)
// is this overkill? hell yeah. is it slow? hell yeah. does it work? hell knows.
float rnd1 = (rand()%10001) * 0.0001f; // four
float rnd2 = (rand()%10001) * 0.0001f; // randoms
float rnd3 = (rand()%10001) * 0.0001f; // from
float rnd4 = (rand()%10001) * 0.0001f; // 0 to 1
bool blue_moon = (rnd1 > 0.58); // 42% chance
bool pink_elephants_fly = ((int)(rnd2 * 100) % 3 == 0); // if rounded random number 1-100 is a multiple of 3; 33% chance
bool snowing_in_july = (rnd3 * timeValue) > 0.08; // approx 50%, more if the game is running slow, 0 if it runs too fast
int power_level = (rnd4 < 0.2) ? 9001 : 8999; // 20% chance
if ((blue_moon && pink_elephants_fly) || (power_level > 9000 && snowing_in_july)) // about 14% chance of spawn
if (m_hostileCount < c_hostileMax)
if (rand() % 2 == 0)
cooldownCounter = 200; // frames between spawns, 100 is about 1.5 seconds depending on framerate
cooldownCounter += 4; // minimum frames between attempts at spawning, regardless of whether anything spawns or not
Yes, this code works. And I don't think it's the worst code in the project, FYI. There were (honestly) the following declarations in the code:
int *xPos= newint;
int *yPos= newint;
Oh, looking through the source I also found this gem.
if (abs(pos.x) > m_spaceSize.x || abs(pos.y) > m_spaceSize.y || abs(pos.z) > m_spaceSize.z)
// object has transcended the space-time continuum (actually just really far away)
Edit: Heck, I'm on a roll and back for more. These are from a C# (non-education-related) project.
///<summary>/// Yes, this is little more than a List<FileInfo>, but so what?
public FileBucket(byte MaxFiles)
if (MaxFiles == byte.MaxValue)
MaxFiles--; // noone will notice
this.MaxFiles = MaxFiles;
None, // don't worry (maybe i should; this mode makes no sense)
SlideIn, // whole slide appearing
SlideVisible, // whole slide is visible
return; // the "SCREW YOU ALL ILL FIX IT SOON" response
I use jokes in the comments (the workaround comments are generally very ironic), and in a reviewed code when commenting what's wrong with that particular piece. Because it's marked TODO, and to be soon fixed by a recipient. But I slip an occasional 'obviously' (as in 'this code does that.. obviously) or 'should be doing' variations.
List<decimal> fixedDenominations = ...
double fixedDenArray = newdouble[fixedDenominations.Count];
int i = 0;
//this is a very nice way to do this, but I choose not to use it because I want that the person
//who reads my code can understand what I'm trying to do
//fixedDenominations.ForEach(d => fixedDenArray[i++] = (double)d);
foreach (decimal d in fixedDenominations)
fixedDenArray[i++] = (double)d;
I remember the time I had started my career in a small company, when no source control exists. We use to back up the folders everyday as old, new, _Date etc. Once it reached its height when a back up folder was created as "latestold" (???)
The only time I ever attempted to add a joke as a comment was in an attempt to hide the embarrassment of using a 'GOTO' statement in some vba code was writing (about 100 years ago); can't remember the joke!
for the record: That was the first and last time I ever used a GOTO statement
Hi all, Though I really like to write funny words whereever I get chances but I don't do this when it comes to coding. But, one of my team mate does a lot. Specifically, whenever he is having a tough time with our boss then he abuses him in the code comment region. He must thank to god that the boss does not read the code too often.
There is no foolish question, there is no final answer...
I know people who've put nasty words in error messages for their own amusement only to forget to change them when it goes live, and the day that message pops up !!!! Something along the lines of 'This cr*p system I was asked to write has broken' - or even something more personal !!
Then again, 99.999% of the time, no one reads my code other than team members. The second it gets out of that zone, its all white, precision, professional, clinical.
If the post was helpful, please vote, eh!
Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ
<span style="color:Red">Now and forever, defiant to the end.</span> What is <a href="http://en.wikipedia.org/wiki/Multiple_sclerosis">Multiple Sclerosis</a>[<a href="http://en.wikipedia.org/wiki/Multiple_sclerosis" target="_blank" title="New Window">^</a>]?
The second it gets out of that zone, its all white, precision, professional, clinical.
What a shame I'm thinking that a majority of people would rather have something amusing to view instead of the usual non-informative crap. i.e. Imagine: "Whoops, seems you've done something totally unexpected...good job" instead of "System error"
All of my code will eventually be seen by the customer.... Now if your code stays internal always you have a bit more flexibility to have fun... but if your bosses and or customers see your code.... then you probably want to be a bit more serious....
_________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
...when your code is going to be (or likely to be) scrutinised by customers and/or (even worse) standards/approvals bodies, everything has to be kept "professional" in tone.
On the other hand, the people who put together the instruction set for the PowerPC must have had a laugh when they came up with the assembler instruction Enable In-order Execution of I/O (short name EIEIO).
In one company for which I worked, a group of disenchanted engineers broke off and formed their own competing company. This was apparently because of a conflict with a person whose initials I will call "ABC" (initials changed to protect somebody I thought of as a friend). EVERY part of the product - PCBs, sheet metal, plastic work, etc - was stamped with the "code" ABC4Q2. (Sound it out to yourself in private - I'm not going to spell it out any more.) This was in a product that had to get through all sorts of approvals bodies all around the world, too. That makes the code comment thing look a bit lame, really.
Not a joke in the comments, but in the firmware itself: I once worked at a place that was going to be shut-down. We had a guy from the other side of the merger whom we had to deal with that was unbearable and thought our team was supplanting his team. In the firmware I placed a PWM routine that quickly pulsed the LED in morse code: that "David M#### is a total Dick". The chars were XOR-d so it would not show up( by perusing the firmware in a text editor) until the status led pulse routine. It was satisfying to know that the status LED was saying what we all knew.