Thursday, November 30, 2006

Avoiding the Evaluate function

There is a good description about what is going on with the use of the evaluate function behind the scenes.

I still have one question after reading this that I'm sure somebody has already investigated. Do we pay the extra overhead for each occurrence of evaluate in a page, or just once? I don't mind so much if I'm just paying it once for 50 instances on a page. If the parser is getting invoked 50 times, I think I'm hunting them down and changing them.

ColdFusion MX 7 -- Avoiding the Evaluate function -- Version 7

Monday, November 27, 2006

filBuf bug

One of my cohorts is attempting to diagnose a filbuf issue on one of our production servers. It doesn't appear to be a coldFusion bug per se. It looks like it's probably an issue with the xmlparser that ships with cfmx6.1.

From my co-worker:

Here's a coldfusion file that demonstrates the issue and also includes my super lame hack for fixing it. all the fix does is put spaces around the brackets, since it's the >] and ]> constructs that seem to cause the error. if you're interested in the java file that demonstrates the problem when run under the JRE that comes with cfmx6.1, I can provide that, too.


<cfparam name="url.fixforwddx" default="false">

<cfsetting requesttimeout="1200">
<cfflush interval="100">

<cfset chars = "]]>">
<cfset chars2 = "">
<cfloop from="1" to="20000" index="i">
<cfset chars2 = chars2 & chars>
<cfwddx action="cfml2wddx" input="#chars2#" output="mywddx">

<cfif url.fixforwddx>
<cfset mywddx = fixForWDDX(mywddx)>
</cfif>
<!--- make sure both the deserialization and the check for wddx work --->
<!--- NOTE: add ?fixforwddx=true to the URL to apply the fix and see this not throw an error --->
<cfset y = isWDDX("#mywddx#")>
<cfwddx action="wddx2cfml" input="#mywddx#" output="z">


<cfoutput>#i# iswddx? #y#</cfoutput>
</cfloop>


<cffunction name="fixForWDDX">
<cfargument name="text">
<cfset var text2 = "">
<cfset text2 = replace(text,"]>"," ] >","ALL")>
<cfset text2 = replace(text2,">]","> ] ","ALL")>
<cfreturn text2>
</cffunction>


Any help greatly appreciated.

Tuesday, November 21, 2006

Handy user defined functions

Here are a few handy user defined functions that help with traditional form controls. Well, actually it's one udf and two variations on a theme.

They let you pass either a boolean value or two simple values that will be tested for equality.

You just use them in place of the attribute of the corresponding name in things like checkboxes, radio buttons and select controls. I always hated that embedded cfif approach. It always seems to flip out whatever editor you're using because of the nested angle brackets.


<cffunction name="checked">
<cfargument name="v1" />
<cfargument name="v2" />
<cfset var attrib = "" />

<cfif NOT structExists(arguments,"v2")>
<cfif IsBoolean(arguments.v1)>
<cfif arguments.v1>
<cfset attrib = 'checked="true"' />
</cfif>
<cfelse>
<cfthrow message="The parameter passed to the checked udf was not boolean" />
</cfif>
<cfelse>
<cfif arguments.v1 eq arguments.v2>
<cfset attrib = 'checked="true"' />
</cfif>
</cfif>

<cfreturn attrib />
</cffunction>

<cffunction name="selected">
<cfargument name="v1" />
<cfargument name="v2" />
<cfset var attrib = "" />

<cfif NOT structExists(arguments,"v2")>
<cfif IsBoolean(arguments.v1)>
<cfif arguments.v1>
<cfset attrib = 'selected="true"' />
</cfif>
<cfelse>
<cfthrow message="The parameter passed to the selected udf was not boolean" />
</cfif>
<cfelse>
<cfif arguments.v1 eq arguments.v2>
<cfset attrib = 'selected="true"' />
</cfif>
</cfif>

<cfreturn attrib />
</cffunction>

<cffunction name="disabled">
<cfargument name="v1" />
<cfargument name="v2" />
<cfset var attrib = "" />

<cfif NOT structExists(arguments,"v2")>
<cfif IsBoolean(arguments.v1)>
<cfif arguments.v1>
<cfset attrib = 'disabled="true"' />
</cfif>
<cfelse>
<cfthrow message="The parameter passed to the DISABLED udf was not boolean" />
</cfif>
<cfelse>
<cfif arguments.v1 eq arguments.v2>
<cfset attrib = 'disabled="true"' />
</cfif>
</cfif>
<cfreturn attrib />
</cffunction>

Tuesday, November 07, 2006

Named parameters, OH YEAH!

Hallelujah! Named parameters in cfstoredproc. I've been looking for this fix for so long now, I'd almost given up. I expect my ex will be on the phone any minute now ;) (fat chance). Thanks Adobe. Now, if only I wasn't working on mx6.1 all over the place. I guess I just need to do a little more flex work for the suits.

Monday, November 06, 2006

CFC Fight Club Rules



A bit of a rant, but lets have some fun with it. I have lots of candidates for numbers 7 and 8. Any thoughts on what they should be? Preferably framework agnostic.



  1. 1st Rule: You do not reference external scopes in a component.

  2. 2nd Rule: YOU DO NOT REFERENCE EXTERNAL SCOPES IN A COMPONENT.

  3. 3rd Rule: Always use "var" for private variables in your methods including loop counters and query names

  4. 4th Rule: Always explicitly scope references to the arguments scope.

  5. 5th Rule: Always create an "init()" method to get your component started. Avoid the use of the implicit constructor since it can't take arguments.

  6. 6th Rule: Avoid using the "this" scope unless it is for something you KNOW is never going to change. Otherwise, code that uses your cfc will be susceptible to errors caused by changes in your cfc code.

  7. 7th Rule:

  8. 8th Rule: