Click here to Skip to main content
15,886,799 members

Survey Results

Do you ever add jokes in code comments?   [Edit]

Survey period: 26 Jul 2010 to 2 Aug 2010

Maybe you're a frustrated comedian, maybe you know your co-worker will get a kick and maybe you're just bored. Do you do it?

OptionVotes% 
Yes, regularly545.70
Yes, occasionally19820.89
Yes, rarely27228.69
No42444.73



 
GeneralFrom a Uni project Pin
codemunkeh2-Aug-10 14:44
codemunkeh2-Aug-10 14:44 
(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)
{
	static int cooldownCounter; // minimum number of calls between spawns
	if (cooldownCounter > 0)
		cooldownCounter--;
	else
	{
		// if no enemies, spawn one (for the hell of it)
		if (m_hostileCount == 0)
			spawnHostile();

		// 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)
			{
				CConsole::Instance()->Write(L"Random spawn!");
				if (rand() % 2 == 0)
					spawnHostile();
				else
					spawnAsteroid();
				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= new int;
int *yPos= new int;

Unsure | :~

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&lt;FileInfo&gt;, but so what?
/// </summary>
internal class FileBucket

public FileBucket(byte MaxFiles)
{
    if (MaxFiles == byte.MaxValue)
    // oshiznit...
        MaxFiles--; // noone will notice
    this.MaxFiles = MaxFiles;
}

internal enum AnimMode
{
    None, // don't worry (maybe i should; this mode makes no sense)
    SlideIn, // whole slide appearing
    SlideVisible, // whole slide is visible
    (snip)
};

if (!RendererReady)
    return; // the "SCREW YOU ALL ILL FIX IT SOON" response


Ninja (the Nerd)

Confused? You will be...

GeneralI always have to think about this great blog post... Pin
GameCrash2-Aug-10 10:53
GameCrash2-Aug-10 10:53 
GeneralI do it occaisionally.... Pin
Keith Barrow1-Aug-10 7:30
professionalKeith Barrow1-Aug-10 7:30 
GeneralIs that the commented jokes help the other developers. Pin
Md. Marufuzzaman1-Aug-10 3:22
professionalMd. Marufuzzaman1-Aug-10 3:22 
Generalsure! Pin
Federico Sasso30-Jul-10 3:52
Federico Sasso30-Jul-10 3:52 
GeneralWhy bother? Pin
R. Giskard Reventlov29-Jul-10 21:27
R. Giskard Reventlov29-Jul-10 21:27 
Generalplease help me about oracle with c#.. Pin
ahmedatas29-Jul-10 20:49
ahmedatas29-Jul-10 20:49 
GeneralRe: please help me about oracle with c#.. PinPopular
Smart K829-Jul-10 21:15
professionalSmart K829-Jul-10 21:15 
GeneralRe: please help me about oracle with c#.. Pin
ahmedatas18-Oct-11 4:53
ahmedatas18-Oct-11 4:53 
GeneralUnfortunatelly pretty often Pin
Smart K829-Jul-10 19:57
professionalSmart K829-Jul-10 19:57 
GeneralDid it once or twice (but not for submitted HW or exam) Pin
Surgeoneer29-Jul-10 12:01
Surgeoneer29-Jul-10 12:01 
GeneralOne liners Pin
Ben Daq28-Jul-10 22:57
Ben Daq28-Jul-10 22:57 
GeneralRe: One liners Pin
PIEBALDconsult29-Jul-10 3:43
mvePIEBALDconsult29-Jul-10 3:43 
GeneralRe: One liners Pin
andre1234529-Jul-10 6:59
andre1234529-Jul-10 6:59 
GeneralNo Pin
Shi,Yudi28-Jul-10 19:58
Shi,Yudi28-Jul-10 19:58 
GeneralRe: No Pin
luisnike1930-Jul-10 15:51
luisnike1930-Jul-10 15:51 
GeneralRe: No Pin
Shi,Yudi30-Jul-10 19:50
Shi,Yudi30-Jul-10 19:50 
GeneralOnly in error messages... Pin
robertw01928-Jul-10 14:11
robertw01928-Jul-10 14:11 
Generalonly during code reviews... PinPopular
M i s t e r L i s t e r28-Jul-10 10:04
M i s t e r L i s t e r28-Jul-10 10:04 
GeneralAn actual joke from my code... sort of Pin
Camilo Sanchez28-Jul-10 4:21
Camilo Sanchez28-Jul-10 4:21 
GeneralNo jokes Pin
Zakaria Butskhrikdize27-Jul-10 23:39
Zakaria Butskhrikdize27-Jul-10 23:39 
JokeNaming Folders Pin
Jobless Creature27-Jul-10 23:34
professionalJobless Creature27-Jul-10 23:34 
GeneralNo, but sometimes people joke about my code Pin
MehZaNet27-Jul-10 20:20
MehZaNet27-Jul-10 20:20 
GeneralHelps break the monotony Pin
Mike Hankey27-Jul-10 7:38
mveMike Hankey27-Jul-10 7:38 
Generalin an attempt to hide the embarrassment of using a 'GOTO' statement Pin
Patrick.Hartnett27-Jul-10 6:46
Patrick.Hartnett27-Jul-10 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.