Why you will never read my blog again...

I was cleaning up my "testingzone" folder today when I ran across some pretty darn old code. (My testingzone folder is where I put all my random tests. My thinking was that it would keep the rest of my web root clean. Of course now my testingzone folder is almost unreadable.) This application was created in 1998, back when IE was the best browser (well in my opinion Netscape had really begun to slip) and ColdFusion was still at version 4.

Oh - and its back when I thought code in all caps was really cool and actually readable.

So first check out the demo:

Dr Confusion

Check out the browser requirements. Check out the "Team Allaire". Talk about ancient history! The application works on a very simple keyword basis. I set it up so that you would create a group of keywords (dogs,dog,canine,etc) and a list of responses. When a match to a keyword was made, a random response is picked.

Back when I wrote this there was no XML parsing so I made the dubious choice of using line breaks for my data structure. Here is a snippet from the data file:

paranoia
paranoid

You're not paranoid if they really <I>are</I> out to get you.
Who is that behind you?

fear
scared
afraid

You must learn to overcome your fears.
Fear is natural, we must learn to accept our fears if we are to truly enjoy life.
Fear is a four letter word.

you

Let's talk about you, not me.
You would find my life very boring, let's talk about you instead.
Who is the doctor here?
This conversation is about you, not me.

Notice how the logic is - list of keywords, blank line, list of responses. Not what I'd consider best practice. Back in CF4 I believe they had INI file functions. I would have used that if I had thought it out better.

Now for some code. Here is what I wrote to parse in the data file:

<!--- Static Variables --->
<CFSET ELIZADAT = "eliza.dat">
<CFSET OVERRIDE = TRUE>

<CFIF NOT IsDefined("Application.KEYWORDS") OR OVERRIDE>
   <CFFILE ACTION="Read" FILE="#ExpandPath(ELIZADAT)#" VARIABLE="BUFFER">
   <CFSET Application.KEYWORDS = ArrayNew(1)>
   <CFSET Application.RESPONSES = ArrayNew(1)>
   <CFSET Application.NULLRESPONSES = "">
   <CFSET Application.NOTHINGRESPONSES = "">
   
   <CFSET NL = Chr(10)><CFSET NL2 = Chr(13)>
   <CFSET NEWLINE = NL2 & NL>
   <CFSET DOUBLE_NEWLINE = NEWLINE & NEWLINE>
   <CFSET BUFFER = Replace(BUFFER,DOUBLE_NEWLINE,"@","ALL")>
   <CFSET ONKEY = TRUE>
   <CFSET LASTKEY = "">
   <CFSET CURRX = 0>
   <CFLOOP INDEX=CURRLINE LIST="#BUFFER#" DELIMITERS="@">
      <CFSET CURRLINE = Replace(CURRLINE,",","&COMMA;","ALL")>
      <CFSET CURRLINE = Replace(CURRLINE,NL,",","ALL")>
      <CFIF ONKEY>
         <CFSET LEN = IncrementValue(ArrayLen(Application.KEYWORDS))>
         <CFSET Application.KEYWORDS[LEN] = CURRLINE>
         <CFSET CURRX = CURRX + 1>
         <CFIF CURRLINE IS "NULL"><CFSET Application.NULLX = CURRX></CFIF>
         <CFIF CURRLINE IS "NOTHING"><CFSET Application.NOTHINGX = CURRX></CFIF>
      <CFELSE>
         <CFSET LEN = IncrementValue(ArrayLen(Application.RESPONSES))>
         <CFSET Application.RESPONSES[LEN] = CURRLINE>
      </CFIF>
      <CFSET ONKEY = NOT ONKEY>
   </CFLOOP>
</CFIF>

Wow - I think my eyes are actually bleeding. I'm not sure why I left override on (it's off now). I just noticed - I used caps for tags, normal case for functions. I seriously must have been on crack back then.

Comments

That looks really awful Ray. But pretty nice funcionality though ;-)

Back in CF 4 I was impressed you didn't surround your variables with #'s
# Posted By Marcos Placona | 4/19/07 10:14 AM
I'll still read the doctor asked it I was crazy so I tried to tie him up but he left. Oh well, atleast you 9 year old code is giving you nightmares and not code you wrote 13 months ago, like me.

But then again I only started writing CF 15 months ago, and I'm still scared to post code.
# Posted By John Ramon | 4/19/07 10:15 AM
"Oh - and its back when I thought code in all caps was really cool and actually readable."

You know...it really was readable. Really. Until we started writing everything lowercase to keep up with the standards. Now you're right - it makes the eyes bleed just a little. :-)
# Posted By Rob Wilkerson | 4/19/07 10:36 AM
It seems that this line:
<CFSET DOUBLE_NEWLINE = NEWLINE & NEWLINE>
...provides a savings of 3 characters per use. However, you only used it one time, so if you actually used more characters by using the CFSET. But creating the double_newline for the replace method was much easier to read overall, so maybe that's ok. It just struck me as funny that there is no apparent way to shorten "DOUBLE_NEWLINE" without losing readability.
# Posted By Dan Sorensen | 4/19/07 10:39 AM
CRACK=Very.DANGEROUS.DRUG....

Though, I have to admit, i read some of the stuff I wrote....last NIGHT and I ask myself what in the name of all that is holy was I thinking about, so if you're able to look back at the stuff from 5 YEARS ago and laugh, you're in good shape...
# Posted By Neil | 4/19/07 11:27 AM
You sir, are a brave man for posting that!
# Posted By Sensei Loco | 4/19/07 11:42 AM
God, that is hard on the eyes. I was still writing uppercase code up until sometime in 2006, when Ray mentioned case in one of his posts. So, I decided to get with the times. I remember how hard it was to force myself to write in lowercase. Thanks for kicking me into modernity!
# Posted By Tom Mollerus | 4/19/07 11:46 AM
When I first started CF a couple years ago uppercase was really easy to read, now it just gives me a headache within 10 seconds of seeing it :)
# Posted By DK | 4/19/07 12:24 PM
Man, I remember the death clock. When I first saw it, I remember thinking that you were some goth hax0r. Little did I know. ;o)
# Posted By Rey Bango | 4/19/07 1:48 PM
Hey, I'm goth! And cool! Yeah, really. Um. Maybe not so much...
# Posted By Raymond Camden | 4/19/07 1:54 PM
I found my old CF 2.0 disks (yes floppies, 3 of them) a couple of months ago. They were in a binder sleve along with some printed code. The print said the filename was 'index.dbm', and I too apparently wrote every command in caps.. only these we DBIF, DBQUERY, etc. Fun stuff.
# Posted By Mike V | 4/19/07 3:31 PM
Team Allaire...the name seems vaguely familiar...

BTW: I LIKE TO WRITE CODE IN CAPS. that is all.
# Posted By Aaron Z. Ward | 4/19/07 3:59 PM
Yeah. Those guys were pretty cool and man they knew their stuff. Wish I could've met some of them! ;)
# Posted By Rey Bango | 4/19/07 4:07 PM
Ray Camden != GOTH - {roflmao}
# Posted By Sid Wing | 4/19/07 4:08 PM
One thing hasnt changed since then... Ray's still asking for donations!
# Posted By TJ Downes | 4/19/07 7:24 PM
Back then I think we all wrote in that style. Looking in the Advanced ColdFusion Application Development 4.0 book all the examples show tags in uppercase which is probably where most of us copied the style.
# Posted By Doug McCaughan | 4/22/07 2:54 PM
Ugh, yeah, I did uppercase tags in ColdFusion AND HTML, then attributes and functions were lowercase.

Most of my CF5 apps are still in production, and when it comes time to do tweaks or feature additions, it is painful. I swear I spend 50% of the time adding the new features, and 50% just trying to clean up code a bit, so that I'm not COMPLETELY ashamed of it. :-)
# Posted By Joshua Curtiss | 4/23/07 2:39 PM
Eliza FTW! I remember writing that program (from a book, of course - I was only a kid then) years ago on my parents Vector.
# Posted By Jeff Rountree | 4/23/07 11:37 PM