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
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
<question", "Bah!", 1, 1, vbTextCompare)
Loop
Do Until InStr(1, sXML_Input, "Bah!", vbTextCompare) = 0
<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;-)
You should check out the daily wtf (thedailywtf.com). All kinds of gold in that mine.
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... :)
Once upon a time, I saw this in some production C code:
define THEISM_BLIGHTS_HUMANITY 1
...
@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.
Taken from thedailywtf.com/.../...er_Friday_Smorgasbord_.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
/* ... */
}
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.
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()'
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.
An autocomplete function :
public List <isearchresult ISpyWithMyLittleEyeSomethingThatStartsWith(string prefix) {...}.
:)
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);
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 <t>
string body = message.Body.ToString();
string [] bodyparts = body.Split(',');
string head = bodyparts[0]
Comment preview