Raymond Camden's Blog Rss

Why you will never read my blog again...

18

Posted in ColdFusion | Posted on 04-19-2007 | 2,104 views

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:

view plain print about
1paranoia
2paranoid
3
4You're not paranoid if they really <I>are</I> out to get you.
5Who is that behind you?
6
7fear
8scared
9afraid
10
11You must learn to overcome your fears.
12Fear is natural, we must learn to accept our fears if we are to truly enjoy life.
13Fear is a four letter word.
14
15you
16
17Let's talk about you, not me.
18You would find my life very boring, let's talk about you instead.
19Who is the doctor here?
20This 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:

view plain print about
1<!--- Static Variables --->
2<CFSET ELIZADAT = "eliza.dat">
3<CFSET OVERRIDE = TRUE>
4
5<CFIF NOT IsDefined("Application.KEYWORDS") OR OVERRIDE>
6    <CFFILE ACTION="Read" FILE="#ExpandPath(ELIZADAT)#" VARIABLE="BUFFER">
7    <CFSET Application.KEYWORDS = ArrayNew(1)>
8    <CFSET Application.RESPONSES = ArrayNew(1)>
9    <CFSET Application.NULLRESPONSES = "">
10    <CFSET Application.NOTHINGRESPONSES = "">
11    
12    <CFSET NL = Chr(10)><CFSET NL2 = Chr(13)>
13    <CFSET NEWLINE = NL2 & NL>
14    <CFSET DOUBLE_NEWLINE = NEWLINE & NEWLINE>
15    <CFSET BUFFER = Replace(BUFFER,DOUBLE_NEWLINE,"@","ALL")>
16    <CFSET ONKEY = TRUE>
17    <CFSET LASTKEY = "">
18    <CFSET CURRX = 0>
19    <CFLOOP INDEX=CURRLINE LIST="#BUFFER#" DELIMITERS="@">
20        <CFSET CURRLINE = Replace(CURRLINE,",","&COMMA;","ALL")>
21        <CFSET CURRLINE = Replace(CURRLINE,NL,",","ALL")>
22        <CFIF ONKEY>
23            <CFSET LEN = IncrementValue(ArrayLen(Application.KEYWORDS))>
24            <CFSET Application.KEYWORDS[LEN] = CURRLINE>
25            <CFSET CURRX = CURRX + 1>
26            <CFIF CURRLINE IS "NULL"><CFSET Application.NULLX = CURRX></CFIF>
27            <CFIF CURRLINE IS "NOTHING"><CFSET Application.NOTHINGX = CURRX></CFIF>
28        <CFELSE>
29            <CFSET LEN = IncrementValue(ArrayLen(Application.RESPONSES))>
30            <CFSET Application.RESPONSES[LEN] = CURRLINE>
31        </CFIF>
32        <CFSET ONKEY = NOT ONKEY>
33    </CFLOOP>
34</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

[Add Comment] [Subscribe to 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
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.
"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. :-)
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.
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...
You sir, are a brave man for posting that!
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!
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 :)
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)
Hey, I'm goth! And cool! Yeah, really. Um. Maybe not so much...
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.
Team Allaire...the name seems vaguely familiar...

BTW: I LIKE TO WRITE CODE IN CAPS. that is all.
Yeah. Those guys were pretty cool and man they knew their stuff. Wish I could've met some of them! ;)
Ray Camden != GOTH - {roflmao}
One thing hasnt changed since then... Ray's still asking for donations!
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.
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. :-)
Eliza FTW! I remember writing that program (from a book, of course - I was only a kid then) years ago on my parents Vector.

[Add Comment] [Subscribe to Comments]