It wasn’t that Jim minded initiating interns into the world of web development, in fact, he viewed the challenge as a very satisfying experience. However, when the newest intern, Stefan, declared on his first day “I don’t want to be labeled as programmer for the rest of my life. Programming sounds too nerdy. I solve problems.” and that despite his ColdFusion experience, he had previously hosted raves and dance parties in his younger days (to further distance him from any chance of being considered a nerd). In short, Jim knew that he had a special case on his hands.

Rather than bruise Stefan’s apparently sensitive ego and give him an assignment that might involve invoicing or user security auditing, Jim handed Stefan a technical, yet practical, task - write a program to get the daily weather reports from a government website and store them locally so that users could see a cached copy rather than pulling it off the weather website each time.

After the assignment was completed, and it had been up and running for a while, a bug was filed as the first S was missing from "SAN FRANCISCO" however, as it turned out, several other cities had been affected as well.

OSTON
HICAGO
IAMI
EW YORK
ASHINGTON
AN DIEGO
AN FRANCISCO
AMPA
...

Upon receipt, Stefan sprang into action, this was his bug and he was going to squash it good.  So, after pushing out a fix within a few hours, he declared the problem 'solved' by adding:

<cfset weather = "S"&weather>

While the fix addressed a few of the problems, after the change was published, it was quickly apparent that Stefan fixed his test cases, but for many other cities, only made the problem worse.

SOSTON
SHICAGO
SIAMI
SEW YORK
SASHINGTON
SAN DIEGO
SAN FRANCISCO
SAMPA
...

Jim offered to assist, treating this as a teaching opportunity on root cause analysis but Stefan dismissed Jim’s offer. Stefan solved problems and this problem one nut that would not escape him. Once again, as more bug reports were filed about the extra S in front of other areas he fixed his fix to limit the 'S' to the west coast.

<cfif i is "west.txt">
  <cfset weather = "S"&weather>
</cfif>

But the gains were quite small...

OSTON
HICAGO
IAMI
EW YORK
ASHINGTON
SAN DIEGO
SAN FRANCISCO
AMPA
...

After several additional iterations, it became apparent that Stefan was starting to have problems following his own code with its nested replaces and loops that mysteriously started at “3” and the 4-pipe delimited string (which doesn’t actually work because Coldfusion treats it as a single delimiter).

<cfset var weatherFileList = "midwest.txt,northeast.txt,south.txt,west.txt,rockies.txt">
<cfset var weatherSavePath = "f:\pathtosite\">

<cfloop index="i" list="#weatherFileList#">
  <cfset weatherFile = GetWeatherFromUrl(i)>
    <cfif weatherFile neq "">
      <cfset firstPrePos = findNoCase("<pre>",weatherFile)>
      <cfset lastPrePos = findNoCase("</pre>",weatherFile)>
      <cfset lastPrePosCnt = lastPrePos-firstPrePos>
      <cfset weatherString = mid(weatherFile,(firstPrePos+5),lastPrePosCnt)>
    </cfif>
   
    <cfset weatherString = replaceNoCase(weatherString,"</pre>","","ALL")>
    <cfset weatherString = replaceNoCase(weatherString,"</pre","","ALL")>
    <cfset weatherString = replaceNoCase(weatherString,replaceNoCase(i,".txt","","ALL"),"||||","ALL")>
    <cfset weatherStringLen = listLen(weatherString,"||||")>
 
    <cfloop index="j" from="3" to="#weatherStringLen#">
      <cfset weather = listGetAt(weatherString,j,"||||")>
      <cfset fileNameExt = left(weather,2)>
      <cfset weather = right(weather,len(weather)-4)>
      <cfset addString="<br/>This forecast provided by the NOAA's National Weather Service (<a target=""_blank"" href=""
http://www.nws.noaa.gov"">www.nws.noaa.gov</a>) and was received at #timeFormat(now(),"HH:mm")#,#dateFormat(now(),"dddd, dd,mmmm, yyyy")#.<br/><br/>"> <cfset weather = replaceNoCase(weather,chr(10),chr(10)&addString,"ONE")>
<cfset weather = replaceNoCase(weather,chr(10),"<br/>","ALL")>
                                   
      <cfif i is "west.txt">
                  <cfset weather = "S"&weather>
      </cfif>
                       
      <cffile action="WRITE" output="#weather#" file="#weatherSavePath##replaceNoCase(i,".txt","","ALL")##fileNameExt#.txt" nameconflict="OVERWRITE">
    </cfloop>
</cfloop>

After Stefan left, the next intern was given the task of resolving some outstanding bugs resulting from Stefan’s code. After one look at the source, the intern new knew better than to try and journey into the madness that was Stefan’s code and promptly threw it away, writing a new working version in about 5 minutes.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!