I want CFGoto!
Posted by Joe Rinehart at 11:09 AM
20 comments - Categories:
ColdFusion MX
Sometimes when I'm working in ColdFusion, I get a little fed up with trying to do things that aren't quite functions, aren't quite objects, and aren't even justifiable custom tags. Things like rendering a specific pod in a stack, or programatically choosing which pods to render.
I'd really like a solution from a much older form of thought to show up in ColdFusion: I'd like to be able to have a given .cfm template jump to any line within itself, run some code, then jump back. This'd include any template it <cfinclude>'d, allowing me to use variables in my <cfinclude /> to do some really dynamic stuff.
I think I'd call it <cfgoto />, and it could jump to any <cfmarker />. Seriously, it's in many high-level languages, why can't we do it in ColdFusion?
This'd be so nice:
<cfloop from="1" to="#arrayLen(pods)#" index="i">
<!--- Forks to the block of code that renders a pod --->
<cfgoto marker="renderPod_#pods.getName()#
<!--- Pod rendering code <cfgoto />'s back to here --->
<cfmarker name="podRenderLoop" />
</cfloop>
Brian Kotek wrote on 08/01/08 11:22 AM
I totally agree, Joe. It's simple things like this that CF is missing that sometimes make me wonder about its long-term viability. GOTO has been around forever, and even though it gets a bad rap, in almost all cases a nice long block of procedural code with some markers in it will run much faster than OO-based code. In the end, raw performance trumps maintainability and modularity every time.