ColdFusion 8 ValueObjects vs Typed Structs for Flex RemoteObjects

March 28, 2008

ColdFusion Objects transfer nicely over to Flex, making the remote data connection for Flex run like a dream.  It can get out of hand, however, when there are a large number of Objects to return from ColdFusion, for example, an array of ValueObjects, which might have other value objects as members.  In researching this, I ran across a few very helpful postings.  Basically, CF8 has a workaround wherein you use typed Structs instead of full blown Objects to pass VO’s to Flex:

http://www.briankotek.com/blog/index.cfm/2008/1/28/Returning-Typed-Structs-vs-CFCs-to-Flex

http://groups.google.com/group/transfer-dev/browse_thread/thread/0abdb2191dcfd226#2cbf827754e75376


So, I decided to run a few very simple tests to see what the impact of CreateObject was on a large dataset.  I put together a CF script with a loop to create 5000 objects using CreateObject (with init), another for 5000 with CreateObject (without init), another to simply duplicate a template Object and another to create 5000 structs.  The breakdown and the code follow:
 

Test

Iterations Elapsed Time (ms) ms/Instance
structTest 5000 157 0.0314
FullCreateTest 5000 17468 3.4936
createTest 5000 16610 3.322
dupeTest 5000 12469 2.4938
structTest 5000 15 0.003


This was run on a CF8 Box with JRun running on Java 1.5 I had similar results on a CFMX 7 Box with JRun running on Java 1.42 The option of rolling query results into typed structs is really a lifesaver given the performance numbers.       

<cfset t1 = GetTickCount() />

<cfset myArray=ArrayNew(1)>
<cfloop from=”1″ to=”5000″ index=”i”>
<cfset newStruct=StructNew()>
<cfset newStruct["iter"] = #i# />
<cfset ArrayAppend(myArray,newStruct) />
</cfloop>
<cfset t2 = GetTickCount() />
<cfset elapse1 = t2 – t1 />
<cfset myArray2=ArrayNew(1)>

<cfloop from=”1″ to=”5000″ index=”i”>
<cfset newObj=CreateObject(“component”,”com.test.TestIter”) />
<cfset newObj["iter"] = #i# />
<cfset ArrayAppend(myArray2,newObj) />
</cfloop>
<cfset t3 = GetTickCount() />
<cfset elapse2 = t3 – t2 />
<cfset myArray3=ArrayNew(1)>

<cfloop from=”1″ to=”5000″ index=”i”>
<cfset newObj2=CreateObject(“component”,”com.test.TestIter”).init() />
<cfset newObj2["iter"] = #i# />
<cfset ArrayAppend(myArray3,newObj2) />
</cfloop>
<cfset t4 = GetTickCount() />
<cfset elapse3 = t4 – t3 />
<cfoutput>Results<br/>Structs : #elapse1# ms for 5000</br>

CreateObject (no init) #elapse2# ms for 5000<br/>CreateObject (with init) #elapse3# ms for 5000<br/></cfoutput>

<cfcomponent name="TestIter">
      <cfproperty name="iter" type="numeric">
      <cffunction name="init">
            <cfreturn this />
      </cffunction>
</cfcomponent>

CFSCRIPT – The little language that …

November 18, 2007

To quote Ben Forta in 2004: “<CFSCRIPT> today is in a strange place. ” (http://www.forta.com/blog/index.cfm?mode=e&entry=1416) I don’t think much has changed in that regard. The fact is, Macromedia ColdFusion stopped partway through the metamorphosis of becoming a scripting language. Kind of like stopping part way through a sex change; the important parts are there, sometimes both sets, and it can be ugly to watch. Now it’s in Adobe’s care, and there are more than just PHP and ASP wandering by and looking at CFSCRIPT, with a mild sense of relief (glad that’s not me) and perhaps a bit of Schadenfreude.

I’ve read articles about Coldfusion programmers jumping ship and running to Ruby on Rails, I wish everyone the best voyage possible, whichever boat they sail. I spent years coding C++ as a plugin to Netscape, to serve up web pages. Then Apache Server. Coldfusion looked like a treat from that vantage point. Despite it’s imperfections, it is a powerful way to make many web applications happen very quickly. That doesn’t change the fact that CFSCRIPT could never run on it’s own. It’s incomplete. Like Pinnoccio, always needing Gepetto around to keep working on him, and no Blue Fairie coming to turn him into a real boy. Yes, CFSCRIPT is in a strange place, and it will likely see out its days in the place that it is.

There is an almost audible sigh of relief that escapes when entering a block of logic which won’t be needing html tags or CFML to make it do it’s job. But eventually the lines of code free of the greater than and less than signs is brought to a screeching halt by one of those things that cfscript just cannot do properly, or requires the esoteric approaches of the guru to get through.

I noticed Sean Corfield’s scripting plugin post, basically allowing a Coldfusion 8 developer to plop in some PHP here, some Ruby there. (a moody person could write alternative verses of PHP and Lua, bringing a Wagnerian feeling to the code). A colleague has been telling me about Groovy, and its possibilities and I stand intrigued. Something will have to yield, one way or another. For things CF could not handle, I used to opt to extend CF with C++ CFX tags. Now, with CF being Java based, it is cleaner to extend with Java (my opinion). Can Groovy solve some problems that CFSCRIPT could not? Is it compelling enough to justify a significant effort in that direction? Groovy and Hibernate play well together (supposedly). I may do a little with Groovy’s Gant (to get past the Ant XML build structure), but beyond that I don’t know. Groovy is too new for risking on my customers, for the time being. But what the future holds, I cannot tell.

As for the rest, I am grateful for having had the chance to work with all of the languages I have. I wish every programmer could have a wide exposure to languages in that way. I feel the same way about natural languages (written and spoken and signed-eg. American Sign Language). The more one can learn about other languages, and their inherent approaches to solving problems, and their implications, the better one can understand and utilize their home language. And though I make fun of different computer languages, I enjoy working with them a great deal.

After doing some work with Lex/Yacc for preprocessing of some code, I did some experimentation with the problem of carrying the cfscript language the distance, by adding “real” classes, to replace the tag based cfcomponent artifact.    Then, adding to that some special system classes that could yield database connectivity and scaffolded views, and cfscript is more complete, operationally.  None of this changes the fact that  CF is locked behind a webserver, and there is no past nor any future for CF based console apps or desktop apps.  It is a backend database application server for the web, when it is doing what it does best.

It is difficult *not* to conclude that Adobe (and perhaps Macromedia) purposefully prevented the completion of the ColdFusion CFSCRIPT “language”.  And given that, it would be interesting to understand exactly why, though one could guess that they don’t want to be a big player in that marketspace, to distract their focus from other more interesting areas.  For the developer who continues to hitch his career on ColdFusion, I would admonish them to add a few additional tools into their toolboxes.


Get Outta my namespace (revisited)

November 18, 2007

Earlier, I discussed some of the problems/issues with Flex Builder’s default configuration of outputting the swf into the “bin” folder. (see Get Outta My Namespace). Operationally, the dot Net server’s claim to the “bin” folder in server root context was one of the roadblocks to use of the “bin” folder. It’s easy enough to use another name, to avoid conditions like this one.

Well, I was recently concerned with the performance of a web application, running on IIS on the JRun4 J2EE server distributed with ColdFusion. I decided to try running the application on a JBoss server, with ColdFusion 8, and do some performance benchmarking, and analysis, to see if the problem’s root was in JRun’s management of the memory objects, or in the tuning of the JRun server, or if the change in platform would make a difference at all. The performance problem is likely rooted in the application’s architecture, and the database configuration, but it was worthwhile and easy enough to see if there was any difference in changing the platform this way.

I have a JBoss 4.05 Server running Tomcat and ColdFusion 8, basically following the easy instructions at Steve Brownlee’s blog when I had first set it up with ColdFusion7, then updating it with ColdFusion 8, using the advice from Adobe. When I attempted to use the Flex application deployed in a “bin” folder which was *not* in the root, that is it was several subfolders away from the root, the server acted as if the html container and the swf file were simply not there. I tried several things before eventually simply renaming the deploy folder to “out”. Immediately, the server recognized the deployed html and swf. I haven’t yet determined what exactly is going on, but I know the bin folder has various application specific uses for JBoss and Tomcat. It seems as though this is interefering, once again, with the default “bin” folder output for Flex deployment. I’ve updated the project, locally, to build to “out” and mapped the application to “out” and it is all working just fine.

As for benchmarking performance, I have started. I’ll try to post anything interesting I might find.


CF8 in Notepad++ (Continued)

October 13, 2007

I’ve uploaded a new package to:

http://labs.soundrage.com/CF8NPP.zip

It includes a chm for CF8 help, the bulk of the size. It’s servicable, but the conversion from html to chm was not perfect.

It includes a script for Inno Setup, which I won’t be able to get back to for a while, so if someone is interested in picking that up, feel free. Otherwise, I’ll get to it when I get to it.  I have it kind of working but for a setup package, that’s really not good enough, and there is a lot more work to be done on it.

The key items of interest are:

1) The shortcuts.xml has a line for launching keyword sensitive help right from the editor to Adobe’s LiveDoc’s or to the local help file. I had to bump the php help off of the F1 key for my own setup, but feel free to do whatever you wish. CTRL-F1 and ALT-F1 launch the help, and highlight the keyword. The shortcuts.xml file needs to be in the folder with your Notepad++.exe, default is C:\Program Files\Notepad++\

2) The keywords themselves are identified in the a\apis\coldfusion8.api file.

3)  The (User App)\Notepad++\InsertExt.ini needs to contain regular expressions to mark the beginning and ending of a function, and how to pick out the function name.  These will show up on the function list, so you can click on the function name and jump straight to it.

[User Languages]
Count User Languages=2
Name 1=ColdFusion8
KeyWBodyBeg 1=
KeyWBodyEnd 1=
MatchCase 1=0
Count Comment 1=3
Comment P1.1.1=
Comment P1.2.1=
Comment P2.2.1=
Count Syntax 1=2
Syntax P1.1.1= Syntax P2.1.1=\"\t.*\>
Syntax P3.1.1=[A-Za-z]*
Syntax P4.1.1=
Syntax P5.1.1=
Syntax P6.1.1=
Syntax P1.2.1=cffunction[\t ]*name[\t ]*\=[\t ]*\"
Syntax P2.2.1=
Syntax P3.2.1=[A-Za-z_]*
Syntax P4.2.1=
Syntax P5.2.1=
Syntax P6.2.1=

4)  Finally, our old friend, UserDefinedlanguages.xml, needs ColdFusion8 set up inside of it.  Basically, you take the contents of UserDefinedLanguages_Coldfusion8.xml, and insert it into the appropriate area inside of the real/active UserDefinedLanguages.xml.  This also sits in the (User App) folder, which is, for me, C:\Documents and Settings\Howard\Application Data\Notepad++\, so yours will be something like that.

I’m posting this over with the Notepad++ people, and will followup there.

For InnoSetup, information can be found at:

http://www.istool.org/    – The extension to InnoSetup, which adds some good stuff.

http://www.innosetup.org/    – The base InnoSetup package.

Hopefully, it will be helpful to someone.  I just enjoyed the diversion for a few hours.


Linux for the Masses?

October 7, 2007

It wasn’t but five or six months ago that I was struck with the sense that it was doubtful that my next computer would be Windows based. There were several reasons for this, and I will try to sum it up quickly without sliding into the sanctimonious sophistry of the sheepherders, who bash Windows for breakfast. And first, I will say that I have some hope that Microsoft will step up and do something to save their products from continued decay, as they were once very good. But wishes are not horses. With internet explorer, Microsoft has had to make the bitter decision between backward compatibility and compliance with standards. A good strategist would have seen the third choice, but they didn’t have one on board when these decisions were made. In choosing to opt for backward compatibility, they have kept open a welcome mat, from the Internet, to an unacceptable number of security risks. I have seen way too many computers, in the past year, plagued with problems created by IE. And the add-on products which were supposed to lock things down failed to address these issues fully, and added problems of their own. Despite their performance in the courtroom, uninstalling IE is a chore.

It seems Microsoft’s concerns have drifted away from the user, and they have become focussed almost solely on their shareholder’s numbers. I noticed, with some chagrin, that the latest my file manager in windows now has a little menu option that says “Is this copy of Windows legal?” Yes, it is, Microsoft. I have the receipt. I have the license key. I’ve hit page down hundreds of times on your legal agreements that relinquish my rights to any sort of complaint for any problem you might cause, keeping an eye out for that clause about my first born, and intellectual property rights to my DNA.

More apropos, “Is this copy of Windows necessary?”

As a developer, I watch as more and more make the mass migration to Apple and OS/X. I have observed the same with non-developer users. And I have had the odious task of watching my wife suffer Windows Vista. The writing seems to be on the proverbial wall. The limits of the 32-bit operating system are being hit, the 4 Gig limit is no longer theoretical, XP64 or Vista Super Deluxe being the Windows options, it is going to be necessary to make an Operating system change in the coming months, regardless of Microsoft’s policies and corporate direction. Virtualization is another trend, which removes some of the barriers of switching operating systems.

The first thought was that I would switch to OS/X, Apple, Macintosh, and that still may happen. But the volume of Linux distributions has led me give it some consideration. A few months remain, maybe even a year, before I absolutely have to make a decision.

Linux options include, the most popular, Ubunto (based on Debian), targetted for the home desktop. Flavors include Kubuntu, Edubuntu, and XUbuntu.

Ubuntu 7.10 - Coming soon

Open Suse, another distro with Ease of Use as a goal:

Fedora, the Red Hat distribution, targetted more at the business desktop:

And a slough of others. If you haven’t, take a peek at DistroWatch:

http://distrowatch.com/