Lost in Code

I try my best to keep the geeky parts of my existence out of this site, but sometimes, there’s a convergence that’s unavoidable.  Case in point: the end of Lost.  I’ve watched it faithfully since its second season, and I’m not sure if there’s ever been a TV show that has been both quarterback-cool and wedgie-worthy.  Like millions of others today, I’ll be glued to the television set, and here’s my silly contribution to the Lost universe.

The code below is written in ColdFusion, and it’s using component architecture, something I’ve recently really come to embrace.  It’s a slapdash concoction that I knocked together in about fifteen minutes, so take it for what it is, a goofy tribute to one hell of a show.  The resulting execution of these bits can be seen here:

http://www.sjwoo.cf-developer.net/lost/default.cfm

The nice indents have been removed by the blog, so it’s not so easy to read the code below.   Not that you’d want to read this, anyway.  Perhaps Daniel Faraday would be interested…

default.cfm

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Lost</title>
</head>

<body>

<!— CFCs —>
<cfobject name=”IslandCFC” component=”lost.cfc.island”>
<cfobject name=”SurvivorsCFC” component=”lost.cfc.survivors”>

<h1>L O S T</h1>

<!— This scope is available as a variable —>
<p>Created by <cfoutput>#IslandCFC.creators#</cfoutput></p>

<!— crash Oceanic 815 —>
<cfset crashedPlane = IslandCFC.crashPlane(“Oceanic”,815)>
<cfoutput>#crashedPlane.message#</cfoutput>

<!— get a list of the survivors —>
<cfset arraySurvivors = SurvivorsCFC.getSurvivors(“#crashedPlane.flightName#”,crashedPlane.flightNumber)>
<p><strong>List of survivors:</strong> <cfoutput>#ArrayToList(arraySurvivors)#</cfoutput></p>

<!— summon smokey, who’ll also kill the chosen survivor —>
<cfset structSurvivors = IslandCFC.summonSmokeMonster(“#ArrayToList(arraySurvivors, ‘|’)#”,”Mr. Eko”)>
<cfoutput>#structSurvivors.message#</cfoutput>
<p><strong>Remaining survivors:</strong> <cfoutput>#ListChangeDelims(structSurvivors.newListOfSurvivors, “,”, “|”)#</cfoutput></p>

<!— summon bombOnSub, which will kill more survivors —>
<cfset structSurvivors = IslandCFC.bombOnSub(“#structSurvivors.newListOfSurvivors#”,”Jin,Sun,Sayid”)>
<cfoutput>#structSurvivors.message#</cfoutput>
<p><strong>Remaining survivors:</strong> <cfoutput>#ListChangeDelims(structSurvivors.newListOfSurvivors, “,”, “|”)#</cfoutput></p>

</body>

</html>

island.cfc

<cfcomponent hint=”The island of Lost and all of its machinations.” output=”false”>

<cfset This.creators = “Carlton Cuse and Damon Lindelof”>

<cffunction name=”crashPlane” returntype=”struct” hint=”Give me the flight info, I’ll crash the plane.”>
<cfargument name=”flightName” type=”string” required=”Yes”>
<cfargument name=”flightNumber” type=”numeric” required=”Yes”>
<cfset var structOutput = StructNew()>
<cfsavecontent variable=”structOutput.message”>
<cfoutput><p>Flight #Arguments.flightName# #Arguments.flightNumber# has crashed on the island.</p></cfoutput>
</cfsavecontent>
<cfset structOutput.flightName = Arguments.flightName>
<cfset structOutput.flightNumber = Arguments.flightNumber>
<cfreturn structOutput>
</cffunction>

<cffunction name=”summonSmokeMonster” returntype=”struct” hint=”Smokey will come out and kill the chosen survivors.”>
<cfargument name=”currentSurvivors” type=”string” required=”Yes”>
<cfargument name=”survivorsToKill” type=”string” required=”Yes”>
<cfset var structOutput = StructNew()>
<cfsavecontent variable=”structOutput.message”>
<cfoutput><p>Smoke monster has been summoned.  He’ll kill #Arguments.survivorsToKill#.</p></cfoutput>
</cfsavecontent>
<cfobject name=”SurvivorsCFC” component=”lost.cfc.survivors”>
<cfset structOutput.newListOfSurvivors = SurvivorsCFC.killSurvivors(“#Arguments.currentSurvivors#”,”#Arguments.survivorsToKill#”)>
<cfreturn structOutput>
</cffunction>

<cffunction name=”bombOnSub” returntype=”struct” hint=”The bomb on the submarine will kill the chosen survivors.”>
<cfargument name=”currentSurvivors” type=”string” required=”Yes”>
<cfargument name=”survivorsToKill” type=”string” required=”Yes”>
<cfset var structOutput = StructNew()>
<cfsavecontent variable=”structOutput.message”>
<cfoutput><p>There’s a bomb on the sub.  It’ll kill #Arguments.survivorsToKill#.</p></cfoutput>
</cfsavecontent>
<cfobject name=”SurvivorsCFC” component=”lost.cfc.survivors”>
<cfset structOutput.newListOfSurvivors = SurvivorsCFC.killSurvivors(“#Arguments.currentSurvivors#”,”#Arguments.survivorsToKill#”)>
<cfreturn structOutput>
</cffunction>

</cfcomponent>

survivors.cfc

<cfcomponent hint=”The survivors of a crashed plane.” output=”false”>

<cffunction name=”getSurvivors” returntype=”array” hint=”A list of the survivors.”>
<cfargument name=”flightName” type=”string” required=”Yes”>
<cfargument name=”flightNumber” type=”numeric” required=”Yes”>
<cfset var arrayOutput = ArrayNew(1)>
<cfset var i = “”>
<cfset var counter = “1”>
<!— if Oceanic 815 —>
<cfswitch expression = “#Arguments.flightName#|#Arguments.flightNumber#”>
<cfcase value=”Oceanic|815″>
<cfloop index=”i” list=”Jack, Kate, Sawyer, Hugo, Jin, Sun, Sayid, Claire, Mr. Eko”>
<cfset arrayOutput[counter] = “#i#”>
<cfset counter = counter + 1>
</cfloop>
</cfcase>
<cfdefaultcase>
<cfset arrayOutput[1] = “No one”>
</cfdefaultcase>
</cfswitch>
<cfset This.arrayOfSurvivors = arrayOutput>
<cfreturn arrayOutput>
</cffunction>

<cffunction name=”killSurvivors” returntype=”string” hint=”Kill the listed survivors.”>
<cfargument name=”currentSurvivors” type=”string” required=”Yes”>
<cfargument name=”toBeKilledSurvivors” type=”string” required=”Yes”>
<cfset var dataOutput = Arguments.currentSurvivors>
<cfset var i = “”>
<cfloop index=”i” list=”#Arguments.toBeKilledSurvivors#”>
<cfset dataOutput = ListDeleteAt(dataOutput, ListContains(dataOutput, i, “|”), “|”)>
</cfloop>
<cfreturn dataOutput>
</cffunction>

</cfcomponent>

Leave a Reply

Your email address will not be published. Required fields are marked *