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:
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:
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.
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.