The rules are simple. Write the worst believable code snippet or small app that you can, in the spirit of amusing, entertaining, or horrifying the reader. Send it as an attachment through the contact form at the bottom of the page. Full rules are at the bottom of this page. The competition ends in approximately one month, Sunday March 13th, giving you one final weekend to write your entry.
Each entry should include both code and, importantly, a description, and so here’s an example of both. (This code was originally written for this forum post.)
Each entry needs a description explaining what the code does, what is bad about it, things that a reader might miss when skimming the code, particularly clever things, particularly dumb things, jokes, etc. Bad puns are particularly welcome and may gain you extra points with the judge. Please go into detail and explain your code so anyone, including those who don’t know Delphi, will understand the point of your submission. For example:
Delphi has a FreeAndNil method, which both frees the object passed in and also sets the reference passed into it to nil. It is equivalent to ‘Foo.Free; Foo := nil;’. It’s the subject of a lot of debate in the Delphi community: one, two, three, four, you get the idea. Clearly – in the Bad Code world – what is needed is not discussion about whether it is used well, but a new implementation of FreeAndNil. This completely misses the point of the debate.
Other things this code does: uses ‘with’ (also very contentious, because it can lead to ambiguous scoping); creates a record instance for the sole purpose of nil-checking; abuses exceptions, raising for a common or non-exceptional case; has an empty exception handler by design; has an Assigned() method that, because of the ENilException in the record constructor, can only ever be called if the object reference is assigned and so always returns true despite its internal logic. Smaller ‘huh?’ moments are that is uses the RTL-inbuilt Assigned() nil-check when checking to raise an exception, but uses ‘if <> nil’ in the Assigned method (why mix two ways to check for nil, and why have an Assigned method – implying knowledge of the inbuilt Assigned() – but not use it there?); and the one sole comment in the code helpfully explains why an exception handler does nothing at all.
TNilChecker = record
FObj : TObject;
constructor CreateFromObj(Obj : TObject);
function Assigned : Boolean;
constructor TNilChecker.CreateFromObj(Obj : Object);
if not Assigned(Obj) then
FObj := Obj;
function TNilChecker.Assigned : Boolean;
Result := FObj <> nil;
procedure FreeAndNil(var Obj : TObject);
with TNilChecker.CreateFromObj(Obj) do
if Assigned do begin
Obj := nil;
on E : ENilException do ; // Obj is already nil, no need for action
Submit anything. Here are some ideas:
- Code your intern who’s only ever used Java would write
- Code your intern who’s only ever used Lisp would write
- Code your colleague who’s never got past TP5.5 would write
- Smallest amount of code for the longest compile time (Eg, “This twenty-line unit takes over two minutes to compile.”)
- Worst abuse of generics
- Worst abuse of RTTI / hacking VMTs / etc
- Mario in 25 lines of code
Submit Your Entry
- Competition is open to anyone, with the exception of where I am legally not able to open it to you, or if you are someone I ask to assist judging, or if the competition or any part of these rules are illegal for competitions in your area.
- Your submission must include:
- A compilable code snippet or small demonstration application in a zip file.
- A good description of the submission (see above for an example and guidelines about what it should include.)
- Your full name and email.
- Your name, submitted code, and parts or all of your description may be published when announcing the runners-up and winner of the competition. You may retain copyright of your entries but grant me to the right to publish your work here and in related places for purposes related to the competition. Your email address will remain private.
- Code may not be harmful when run. Code that is in any way malicious (solely in my judgement) will be instantly disqualified.
- Code should work in a modern version of Delphi – say, XE2 and up. You can change this within reason. I have D7, D2010-Seattle available for testing. Code relying on D2005, D2006, D2007 or D2009 will be tested on other versions.
- The winner and order of runners-up are solely at the judgement of David Millington. Bribes are not accepted, but you’re welcome to send them through to see if it works.
- The winner will win one license of Parnassus Navigator and a copy of SourceOddity FixInsight.
- There may be any number of runners-up. There is no prize for runner-up, but you will get glory and fame. You may also have a copy of Parnassus Bookmarks, if you wish, since it’s free.
- Bonus points may be awarded at the judge’s discretion for bad puns, outrageous flattery, or incredible obfuscation.
- Competition ends Sunday 13th of March, and winners will be announced shortly after, depending on the volume of submissions.