Ayende @ Rahien

It's a girl

Joking in Code

People has started to use the comments of the previous post for putting programming jokes. Let us make this formal. I want to see code that is funny, or jokes in code.

The condition is that it has to be production worthy code. No perl poetry or things that you can do with the language just because you can.

Comments

josh
11/07/2008 01:35 AM by
josh

This was in some very old VB6 COM+ production code, that I yanked when I found it. The dev was in a bad mood at having to learn xml:

Do Until InStr(1, sXML_Input, " <question", vbTextCompare) = 0

i = i + 1

sXML_Input = Replace(sXML_Input, "

<question", "Bah!", 1, 1, vbTextCompare)

Loop

Do Until InStr(1, sXML_Input, "Bah!", vbTextCompare) = 0

sXML_Input = Replace(sXML_Input, "Bah!", "

<question", 1, 1, vbTextCompare)

Loop

This was the best his code was riddled with string manipulation on an XML string (splitting into an array on >< and then loading each element into a dom), that is just to pathetic and sad to post. But any time I need a morale boost I just go reread his old crud;-)

Ken Sykora
11/07/2008 03:34 AM by
Ken Sykora

You should check out the daily wtf (thedailywtf.com). All kinds of gold in that mine.

Francois Germain
11/07/2008 04:29 AM by
Francois Germain

We used to joke a lot around the office when I found out that one of my peer was actually trimming the length of the recordcount property of ADO recordsets all over our import and export back end.

dim rstTest as adodb.recordset

set rstTest = library.sqlserver.getrecordset(strsql)

if len(trim(rstTest.recordcount)) = 0 then

'Do some work

End if

I was so happy when this guy left... :)

xenolinguist
11/07/2008 05:23 AM by
xenolinguist

Once upon a time, I saw this in some production C code:

define THEISMBLIGHTSHUMANITY 1

...

while (THEISM_BLIGHTS_HUMANITY) 

/* obviously, this is always true */

{

    ...

} 
Benny Thomas
11/07/2008 07:47 AM by
Benny Thomas

@Francois Germain

Code like that was in 2 big productionsystems written by a coworker of mine.

One other big issue I had with his codingstyle was his argument for writing long transactional scripts because he liked to see everthing the code did.

He invented his own law to. There should never be more then 3 method steps in code before you find the code that writes the data to the database. His coding was not PI can you say.

Needless to say, I left that company.

Remco
11/07/2008 12:38 PM by
Remco

Taken from thedailywtf.com/.../...erFridaySmorgasbord_.aspx

Scott Stanchfield was tasked with optimizing memory usage in a Java application and found a way to shave a few bytes left in by an intern with a sense of humor ...

public class ValidationMessage

{

//internal members

string messageId;

string messageText;

string helpLink;

/* ... */

double cheeseburger;

char broiled;

long time;

//helper functions

/* ... */

}

Will
11/07/2008 03:01 PM by
Will

It's been a while and since I don't work there anymore I won't be entirely accurate on the method name. But...

At a former company we were doing a code review. I came across a method that looked a little fishy:

private bool ThisIsNotTheContactWeAreLookingFor(...){ ... }

Of course, I raised question of if we should be injecting Jedi mind tricks into our code.

Jesse
11/07/2008 05:16 PM by
Jesse

I have been reviewing an application written by some folks off-site. They took a convention of prefixing classes, methods, members, etc with a common two or three letter prefix related to the business function that the class/method/member supported.

One of the main components of the application deals with 'Assessments', and for some reason they chose to use 'ass' as the prefix. This obviously made for some pretty funny method names, but my favorite so far is a method that loads assessments on the screen, aptly called:

'Private Sub AssLoad()'

Frank Quednau
11/07/2008 07:15 PM by
Frank Quednau

In VB Code I always wrote "On Error Goto Hell". We quite liked the idea in java of writing "throws Shit".

Back in the days when I was in full Procedural steam and wrote a massive servlet handling all sorts of web forms, I used an ASCII-art of the Simpsons Family to separate two sections of the file. Suffice to say, the customer at some point got their hands on the code (also finding the comment "this *** is a dealer" and the int "my***index").

Back then I had to apologize to the customer. What a bunch of humourless saps. I think that's when I got traumatized. Now I only write the bare minimum of code that will do the trick. Oh, and the files are smaller. Reduces the pain.

Yoni Shalom
11/08/2008 04:43 PM by
Yoni Shalom

An autocomplete function :

public List <isearchresult ISpyWithMyLittleEyeSomethingThatStartsWith(string prefix) {...}.

:)

Yoni Shalom
11/08/2008 04:50 PM by
Yoni Shalom

Racist code is sometimes nice too, if taken in right proportions :

function :

public void StartTransfer(IList <object objects);

test code :

IList <object palestinians = /* initialization... */;

StartTransfer(palestinians);

Mike Minutillo
11/09/2008 12:06 AM by
Mike Minutillo

The other day for a demonstration of extension methods I got to write:

public static bool IsIn <t(this T wally, IEnumerable <t crowd )

{

return crowd.Contains( wally );

}

I'm also a big fan of naming things correctly but not getting hung up on it if you can't think of a good name (after all we have refactoring tools) so for a while I had a system with repositories that implemented ICanGetYouA

Karl
11/13/2008 12:48 PM by
Karl

string body = message.Body.ToString();

string [] bodyparts = body.Split(',');

string head = bodyparts[0]

Comments have been closed on this topic.