The Joys of NOT Using CFWDDX

February 19, 2010

I had the pleasure of working an issue just the other day where an internal web application didn’t seem to be responding. At first I suspected some type of bug in environment configuration, or some other type of obscure thing. The app worked in other environments, so that was my first suspicion. After a bit of digging I discovered this little nugget (changed a bit to protect the innocent of course).

<cfwddx action="cfml2js" input="#rc.query#" topLevelVariable="data" />

(more…)

0

Dallas/Ft. Worth CFUG – Adapter and Facade Patterns

February 8, 2010

Join me tomorrow night at the Dallas/Ft. Worth ColdFusion User Group meeting where Dave Shuck will be presenting a beginner’s introduction to ColdSpring and dependency injection, following by yours truly presenting Chapter 7 of the Head First Design Patterns book: Adapter and Facade patterns. There is usually food, nerds, and a chance to network and learn with the best ColdFusion peeps in Dallas!

http://dfwcfug.org/blog/2010/02/05/February-Monthly-Meeting-The-Facade-and-Adapter-Patterns–HFDP-Chapter-7-Adam-Presley

1

PayPal Frustrations

February 5, 2010
Tags:

Today I’ve been working on the final bit of a PHP contract for a client where I am converting an older ASP site to PHP. This phase involves moving over the PayPal code. The API is pretty simple for PayPal actually, and involves sending a POST to a specific API with a specific format. So basically a RESTful service.

I’m not one to just slap up the code and test live, however, and wanted to do some testing first to make sure the work flow for this part of the application is correct. So I’m going over the documentation, admittedly in a hurry, and see that I need to use a sandbox URL. Ok, I try that, but get odd internal errors. I find that odd, but start pouring over a Google Search in an attempt to see who else has seen this and already solved said issue.

After quite a lot of getting nowhere, I finally see something that tells me that you can’t just use the sandbox URL with your normal PayPal credentials. You have to setup a separate sandbox account. Ooookkaaay… Fine.

I set out to do this task, and I create an account. I find this easy enough, and I also find setting up a “cookie cutter” pre-made accout for a buyer easy enough. But when I go to test that using the Website Direct Pay Pro thingie, it complains that my sandbox is not setup correctly. So I start to investigate this. Turns out the pre-baked accounts do not use this, and you have to set one up manually.

FINE. I start that process. I get past page one where I put in my email and password, and accept the terms, and then fill out all of page two with who my “business” is. When I submit this, however, I get a cryptic error. Come to find out my password from the PREVIOUS step is not valid, and it didn’t bother to tell me till I submitted step 2!!

By this point I’m ready to start sniping imaginary targets in thin air with my imaginary finger-rifle. But I move forward. I get the account setup. All I have to do now is verify the information in the email they sent me. Oh do I??? What email!! I asked for it 4 times, and never got it today. Yes, I checked Junk mail.

I’d like to go on the record and wonder how in the world PayPal has become one of the most popular solutions in the world if setting up a dev environment is this … icky!! GAH!

1

2010 Date Nerdiness

February 3, 2010

So my girlfriend and I were discussing some plans we’ve gotta make this year, and started talking about cool dates. You know, like 9/9/1999. The coolest one so far for this year would be 10/10/2010 (ten ten ten).

So anyone who has ever known me knows that not only am I a giant nerd, but I own it. I immediately recognized that 10/10/10 could be represented in binary as 101010. And then I busted out a calculator because I suck at converting binary to decimal. And guess what???

101010 = 42!!!! The answer to the ultimate question of life, the universe, and everything!! How super cool is that?

0

Dynamic Function Invocation – Goodbye Context!

February 3, 2010

Last night I posted about a small, unscientific performance test of various method for dynamically invoking a method. So, for example, if you have a method name stored dynamically somewhere (like a database, or XML document) to be invoked against some component, there are a couple of ways to do it. I demonstrated that one can create a variable reference to a method on a component using evaluate, and then continually invoke the method against the reference.

You should be aware however, that while CF functions are first class citizens, they don’t retain their context.

However, as Mr. Mark Mandel and Mr. Ben Nadel pointed out above I should be careful because the way ColdFusion actually processes CFC methods, creating a “reference” to a method on a component, and invoking it that way means the method loses, or more appropriately changes context. Allow me to illustrate.

Let’s start with a simple CFC that has two methods. The first method is a standard init function to setup the context of our component. In here we will setup a private variable called multiplier. We then have a method called doTest which accepts a single argument, value, and returns the product of value and multiplier. Let’s see that now.

1
2
3
4
5
6
7
8
9
10
11
12
13
<cfcomponent displayname="Test" output="false">
 
	<cffunction name="init" access="public" output="false">
		<cfset variables.multiplier = 10 />
		<cfreturn this />
	</cffunction>
 
	<cffunction name="doTest" access="public" output="false">
		<cfargument name="value" required="false" />
		<cfreturn value * variables.multiplier />
	</cffunction>
 
</cfcomponent>

Simple enough. Now let’s look at using the same method I did last night, and see what happens.

1
2
3
4
5
6
<cfset rc.object = createObject("component", "com.test").init() />
<cfset rc.functionName = "doTest" />
<cfset rc.ptr = evaluate("rc.object.#rc.functionName#") />
<cfset rc.result = rc.ptr(5) />
 
<cfdump var="#rc#" label="Test Results" />

Kaboom!

Kaboom! Context go bye-bye!

Why? I cannot say with any real certainty, except that it seems ColdFusion seems to wrap CFCs in a sort of proxy, each function becoming a Java class, and the proxy simply instantiates and invokes the requested methods. When creating this function reference it seems we lose this proxy container, and thus context (which contains all the necessary scopes).

I say all of that of course only through observation of the call stack, and not much more. Perhaps someone with a bit more knowledge on this subject can shed some light?

6

ColdFusion Dynamic Function Invocation Methods

February 3, 2010

Tonight I was working with a project that a buddy and I are doing on the side in an attempt to make money and I’m reviewing the code he’s got so far to make sure I have a good grasp on everything that’s going on. He’s built his own ColdFusion framework, and it appears pretty solid, if not a bit heavy. As I’m reviewing this code, however, I see that part of the routing code (yes, it’s an MVC framework) is using evaluate to dynamically execute methods. Although I see why this is happening, I’ve always assumed that evaluate was evil. My first thought was “Why isn’t he using CFINVOKE?”. My second thought was “But is that really better??”

Being the curious guy that I am I decided to make a very unscientific test where I would run two sets of code. The first set determines how much time it takes to create an object using createObject, then call a method against that object 100 times using evaluate. For example,

1
<cfset evaluate("someObject.#dynamicName#()") />

The second set determines how much time it takes to execute a method 100 times using just plain old CFINVOKE.

I ran each test 10 times with the following results:

  • Evaluate: average of 267ms
  • CFINVOKE: average of 284ms

The small margin of difference did catch me off guard, as I kind of expected CFINVOKE to perform badly, and evaluate to do much better, even though it is evil.

Then I thought, “How about we create the object, then create a reference to the method?” So something like this.

1
2
3
4
5
6
7
8
9
<cfset start = getTickCount() />
<cfset functionName = "test" />
<cfset o = createObject("MyObject").init() />
<cfset ptr = evaluate("l.o1.#functionName#") />
<cfloop from="1" to="100" index="l.i">
	<cfset ptr() />
</cfloop>
 
<cfset end = getTickCount() />

I ran this 10 times, and got an average of 15.5ms. WOAH!!! Big difference! So there ya go! Remember that ColdFusion is built on Java, and references are a powerful feature! Happy coding!

5

Fisheye Menu with jQuery

January 21, 2010

For those that have a small case of “Mac envy”, this post is for you (and me, honestly). One of the neatest things about the Mac OS user interface is the “fisheye” menu at the bottom of the screen. You know the one, where there is a dock bar with icons on it, and when you mouse over the icons they grow in size, giving the “fisheye” effect. Today we are going to look at a jQuery plugin that makes putting this kind of menu into affect in your websites easy as pie!

(more…)

1

Adobe ColdFusion Community Professional

January 19, 2010
Tags:

While watching a movie on TV last night, Daylight specifically (yes, the one with Sylvester Stallone), I received an email that had me as excited as if I was going to see Metallica in concert. The subject: Welcome to the Adobe Community Professionals program 2010. Needless to say I stayed up WAY too late checking out all of the new, cool stuff I have access to. In fact I could barely sleep, so I had to stay up and play more video games just to get tired!

I would like to thank all of the wonderful people who nominated me, and believe that I have something useful to contribute to the ColdFusion community (you know who you are). :) I will strive to continue being nerdy and excited about ColdFusion development, and hope that I can give some of that excitement to the community!

Thank you all again, and happy coding!

P.S. I’m bringin’ nerdy back.

1