The worst ColdFusion code...ever

Everyone has run across bad code. The world of web development is full of it.

I've seen a lot of ColdFusion code that would make developers cringe, but nothing I've seen rivals the code I found while I was working on a project a while back.

Feast your eyes on this beauty:

<cfset b = 0>
<cfloop query="problemlist">
<cfset b = b + 1>
<cfif b eq 1 or b eq 5 or b eq 9 or b eq 13 or b eq 17 or b eq 21 or b eq 25 or b eq 29 or b eq 33 or b eq 37 or b eq 41 or b eq 45 or b eq 49 or b eq 53 or b eq 57 or b eq 61 or b eq 65 or b eq 69 or b eq 73 or b eq 77 or b eq 81 or b eq 85>
      <tr>
<cfelse>
</cfif>

<td><strong>#name#</strong>
<cfif #ListQualify(opencase.tech_diagnosis,",")# contains #id#>
   <input type="Checkbox" name="diagnosis_problem#i#" value="#id#" checked>
<cfelse>
<input type="Checkbox" name="diagnosis_problem#i#" value="#id#">
</cfif>
</td>

<cfif b eq 4 or b eq 8 or b eq 12 or b eq 16 or b eq 20 or b eq 24 or b eq 28 or b eq 32 or b eq 36 or b eq 40 or b eq 44 or b eq 48 or b eq 52 or b eq 56 or b eq 60 or b eq 64 or b eq 68 or b eq 72 or b eq 76 or b eq 80 or b eq 84>
   </tr>
<cfelse>
</cfif>
</cfloop>

Isn't that beautiful!

Ok, so who has got something better? Anyone?

Related Blog Entries

Comments
Brian Rinaldi's Gravatar It's a good thing they never had more than 88 problems.
# Posted By Brian Rinaldi | 2/15/07 1:31 PM
Dan Wilson's Gravatar Wow,
Pure Crap.
# Posted By Dan Wilson | 2/15/07 1:31 PM
Nick Kwiatkowski's Gravatar I've had one where the old programmer was attempting to parse XML files by hand to generate some reports.

He started by reading the entire file, and searching for certain titles.

He looped through the entire directory doing this. He built a list of XML files that fit his criteria.

Then he re-read the same files, and did a write command to essentially copy them to another directory.

Then he opened each file again, and searched for another parameter in the XML. Stored the file names in a list, and copied them using the same method as before.

He did this four more times. So, he ened up with 6 copies of the file, read EACH sucessful file 6 times.

He was wondering why this particular template took over 30 minutes to run for about 1,000 files.

After cleaning up his code, it ran in under 45 seconds.
# Posted By Nick Kwiatkowski | 2/15/07 1:43 PM
Russell Brown's Gravatar I usualy don't see too much ColdFusion code thats that bad, but holy crap do I see some god awful SQL code out there.
# Posted By Russell Brown | 2/15/07 1:55 PM
Mike Schierberl's Gravatar I found this in an app I inherited a few years ago. The idea was to show the user if ColdFusion was installed correctly as the first step of an application configuration. (Also note the spelling of CF)

<cfif not isDefined("cgi.REMOTE_ADDR")>
   <p><strong><span class="error_normal">Cold Fusion is not installed or not running.</span></strong></p>
<cfelse>
   <p><span class="fntGreen8"><strong>Cold Fusion is running.</strong></span></p>
   <p>Click <strong>next</strong> to continue.<br></p>
</cfif>

I'm taking a wild guess that they never tested the script without cf installed
# Posted By Mike Schierberl | 2/15/07 2:01 PM
Critter's Gravatar Don't you need my written permission before posting my code?
# Posted By Critter | 2/15/07 2:23 PM
Kevin Roche's Gravatar I once had to work on some code that took around 80 lines of CF to
work out whn next July was.
# Posted By Kevin Roche | 2/15/07 4:23 PM
Jeffry Houser's Gravatar I no longer have access to the specific code segment, but the gist was:

<cfif condition>
X
<cfelse>
X
</cfif>

if the condition was true, or false, the same code was executed.
# Posted By Jeffry Houser | 2/15/07 5:58 PM
David Stockton's Gravatar I recently saw a screen scraping system that could quite easily have used an XML parse (and it wasn't just there because of legacy reasons, it had only just been written :o )

Check out http://thedailywtf.com/ for your daily dose of "WTF!s".

No matter how bad it gets I like to check that site to remind me that it *could* be worse!

D
# Posted By David Stockton | 2/19/07 3:12 AM
Travis's Gravatar So, Kevin... how long ago did you write that code? :)
# Posted By Travis | 2/19/07 3:25 PM
Kevin Schmidt's Gravatar It's been awhile...
# Posted By Kevin Schmidt | 2/19/07 3:31 PM
Daveis's Gravatar Yeah but some of Kevin's code is probably still in Production.
# Posted By Daveis | 2/23/07 6:08 PM
Tariq Ahmed's Gravatar One thing I've seen is:

<cfif x eq someValue>
<cfif x eq someValue>
...
</cfif>
</cfif>

an interesting double check... :)
# Posted By Tariq Ahmed | 2/25/07 7:48 PM
Shane Montgomery's Gravatar Mike Schierberl, I nearly spit out my coffee when I saw that. That made my morning.
# Posted By Shane Montgomery | 3/1/07 9:27 AM
Mike's Gravatar You're still using ColdFusion? I gave it up years ago for .NET (C#).

I didn't think anyone was doing CFML anymore
# Posted By Mike | 11/28/07 9:19 AM
Chuck Williams's Gravatar **GASP** Who said that? Who said they gave up ColdFusion?! Sacrilege! You shall be smitten by the Gods of Mt. Adobe!

I've got about 380 MB of the crappiest code in the world! I saw a page recently that went something like this:

<cfhttp url="www.thisSite.com/myPage.cfm?myVariable=set"/>
<cfif url.myVariable EQ "set" >
<cfhttp url="www.thisSite.com/myPage.cfm?myVariable=set2&myVariable2=set1"
</cfif>

The original developer was unavailable for comment - why would anyone do this? The rest of the page didn't even use them in ANY way!?!? I tacked it up to unnecessary legacy code.
# Posted By Chuck Williams | 11/29/07 6:20 AM
programmer required's Gravatar this is a crap idea, why would you openly laugh at a fellow developers work? if i was going to hire a developer and saw that you posted part of someone's site here to giggle at, i wouldn't hire you. i actually only discovered this site as i was checking out someone i was thinking of hiring. so if you post for jobs in a well known programmers job site...You know know who you are!!!
# Posted By programmer required | 5/18/08 6:23 AM
KJ's Gravatar Lol. i found this page browsing for code. this reminds me of my first days when i learnt coding.

<cfif b eq 1 or b eq 5 or b eq 9 or b eq 13 or b eq 17 or b eq 21 or b eq 25 or b eq 29 or b eq 33 or b eq 37 or b eq 41 or b eq 45 or b eq 49 or b eq 53 or b eq 57 or b eq 61 or b eq 65 or b eq 69 or b eq 73 or b eq 77 or b eq 81 or b eq 85 or b eq my grandma has gone to lunch :)>

what a beauty !
# Posted By KJ | 6/28/08 11:40 PM
FX's Gravatar It becomes reference very much. Thank you.
# Posted By FX | 7/10/08 12:08 AM
Questions or comments? Feel free to email me at kevin.schmidt[at]flexinabox.com