|
(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++)
void CGameApplication::randomSpawn(float timeValue)
{
static int cooldownCounter;
if (cooldownCounter > 0)
cooldownCounter--;
else
{
if (m_hostileCount == 0)
spawnHostile();
float rnd1 = (rand()%10001) * 0.0001f;
float rnd2 = (rand()%10001) * 0.0001f;
float rnd3 = (rand()%10001) * 0.0001f;
float rnd4 = (rand()%10001) * 0.0001f;
bool blue_moon = (rnd1 > 0.58);
bool pink_elephants_fly = ((int)(rnd2 * 100) % 3 == 0);
bool snowing_in_july = (rnd3 * timeValue) > 0.08;
int power_level = (rnd4 < 0.2) ? 9001 : 8999;
if ((blue_moon && pink_elephants_fly) || (power_level > 9000 && snowing_in_july))
{
if (m_hostileCount < c_hostileMax)
{
CConsole::Instance()->Write(L"Random spawn!");
if (rand() % 2 == 0)
spawnHostile();
else
spawnAsteroid();
cooldownCounter = 200;
}
}
cooldownCounter += 4;
}
}
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= new int;
int *yPos= new int;
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)
Edit: Heck, I'm on a roll and back for more. These are from a C# (non-education-related) project.
internal class FileBucket
public FileBucket(byte MaxFiles)
{
if (MaxFiles == byte.MaxValue)
MaxFiles--;
this.MaxFiles = MaxFiles;
}
internal enum AnimMode
{
None,
SlideIn,
SlideVisible,
(snip)
};
if (!RendererReady)
return;
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
|
... but sometimes its the code that I'm commenting that is the real joke.
ragnaroknrol The Internet is For Porn[^]
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
I don't think it will help other guys who are starting to work on it.
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
and I always laugh reading them, sometimes year later
|
|
|
|
|
Never seen the point of putting jokes in comments.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
ı need to learn oracle with c#.and ı want to learn it with videos...visual instructions you know..thank you all..
|
|
|
|
|
Come on.. Isn't the one inch bold font saying: DO NOT POST PROGRAMMING QUESTIONS HERE enough ?
The wisdom is to see things truthfully.
|
|
|
|
|
ı dont know how to use this website ,ı m newbie..sorry for that.
|
|
|
|
|
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.
regards,
Kate
The wisdom is to see things truthfully.
|
|
|
|
|
I remember that I put a funny comment for myself in a code while I was practicing.. but I don't do that in assignments or exams.
|
|
|
|
|
Some good one liners help. I usually put then in the above the functions. Also I like to call some local variables silly names some times. Rather than a plain old I for a for, next go for MrLoop etc.
Why is it when you are busy everyone whats it yesterday, But when your not no-one has any work for you?
|
|
|
|
|
Ben Daq wrote: MrLoop
I generally use runner .
|
|
|
|
|
|
Exactly No, I'm conscious of that it'll not give anyone a bit help.
|
|
|
|
|
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand...
luisnike19
|
|
|
|
|
Comments aren't just for others, but the one who written the code in future.
|
|
|
|
|
Sometimes if my code requires throwing an exception, I'll write a small story (like 2 or 3 sentences) telling the what the error in some kind of silly way. is
|
|
|
|
|
I only put jokes in BEFORE code reviews... that way I can see who actually read the code BEFORE the meeting and who is reading the code AT the meeting ...
|
|
|
|
|
List<decimal> fixedDenominations = ...
double[] fixedDenArray = new double[fixedDenominations.Count];
int i = 0;
foreach (decimal d in fixedDenominations)
{
fixedDenArray[i++] = (double)d;
}
|
|
|
|
|
Jokes ???? My code is my expression, I don't want to joke when I'm in code writing process !!!
Zqr
|
|
|
|
|
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" (???)
|
|
|
|
|
Sometimes you do something in the most amusing ways.
I had a situation where I refactored some code and was left with something like this:
if (check1 == true && check2 == true)
{
}
else
{
code was here.
}
|
|
|
|
|
Or if I'm just in the mood.
|
|
|
|
|
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
|
|
|
|