Shaun Mccran

My digital playground

05
N
O
V
2009

Scotch on the road 2009 - London session

I had the luck last week of attending Scotch on the road 2009 in the SwayBar, London. There were quite a few sessions crammed into the day of talks, some taking a more technical approach, others a little more evangelistic. In this article I'll cover the points that I found of particular interest.

Firstly I was struck by how well the ColdFusion community seems to be doing over the last few years. There were several comments as to how many more developers and companies are now using ColdFusion as a development language. It really is encouraging to see that ColdFusion still has a place in the modern development world.

The overall focus of the sessions this time around was ColdFusion 9. Obviously with a big release arriving Adobe are keen to extol its virtues as much as possible. The major differences appear to be some major performance increases, and several additions to the existing functionality.

ORM (Object Relational Mapping) Is the newly integrated Java Hibernate framework. This is pitched as a way of speeding up development time, and avoiding writing repetitive getters and setters in your CFC's. The Java engine handles the entire database layer and frees the developer up to write the actual functionality, rather than endless SQL scripts. At its most basic it is a way of mapping CFC's using the CFProperty tags to a database schema. It's an interesting methodology that I hope to test out soon. (This is known as 'Active record' in many other languages.)

Solr/Verity/Sphinx - The Verity search index is still present but has taken somewhat of a back seat to the new Solr search index. This was something that really piqued my interest as we currently use Sphinx to create large full text search indexes. There are murmurings that that there are some performance differences between Verity and Solr, but it would also be very interesting to see Sphinx thrown into the mix. At some point I hope to run some comprehensive tests against the three to see their performance differences under load.

There has been an interesting change to the Eula this time around too. It isn't something that most people look at, but the licensing model has changed slightly. You can now reuse your ColdFusion 9 license on a non production server. This means that it is very cost effective in upgrading your staging or failover servers, as they can use the same license as your live servers. (For legal reasons don't take my word as gospel, this is how I understood Claude Englebert's presentation on it.)

Another very interesting feature of ColdFusion 9 is its ability to expose a lot of its functionality as external API's. You can now expose specific functions of the server, and it is only a slightly different syntax from the traditional cfml code:

view plain print about
1<cfmail to="peter@parker.com"
2 from="mary.jane@damselInDistress.co.uk"
3 subject="Rescue me please" />

4
5<cf:Mail to="peter@parker.com"
6 from="mary.jane@damselInDistress.co.uk"
7 subject="Rescue me please" />

Overall it was a very informative and thought provoking seminar. Fuzzy orange are to be commended on putting on a great day. I'd highly recommend any of their future events, not just for ColdFusion based developers, but for Adobe affiliates in general.

28
O
C
T
2009

ColdFusion scoping issues and the Var scope

One of the more common problems with a ColdFusion application, especially when it starts to grow or involves more than one developer is variable scoping, and scope bleed through issues. More recently I have had to re examine the framework of an application, in an effort to track and eliminate any instances of this.

Not properly scoping a variable, IE:

view plain print about
1<cfset myUnscopedVar = "Foo">

Forces ColdFusion to add the variable to the 'variables' scope. This scope is available to the entire template. This is even more important when you consider CFC's and the potential damage that a leaked variable could cause. One of the major benefits of OO in ColdFusion is the encapsulation that it provides. As soon as you start declaring un scoped variables, then you lose that.

Mike Schierberl has quite an in-depth blog about this subject, http://www.schierberl.com, he goes into a great deal of depth about this subject, and he has built and maintains the varScoper project. The varScoper allows you to scan your code base for un scoped variables, and after a quick inspection of its output it seems very reliable. I'm not sure its 100% foolproof, but would be a valuable addition to a QA process.

Changes to the Var scope in Coldfusion 9

I am currently not using ColdFusion 9 in any environment; in fact my hosting company is still on 7! That said it appears that there are some significant changes to the Var scope in ColdFusion 9.

Ben Forta sums it up nicely here:

http://forta.com/blog/index.cfm/2009/6/21/The-New-ColdFusion-LOCAL-Scope

He does touch on an interesting point in the article above. I quite like the structured layout of a CFC, and part of that regime for me is declaring all the Vars at the top of a function. It sort of matches the layout of an Action Script class as well, declaring all your constants etc at the top of the script. It is also a very easy coding standard to adopt and enforce if you are part of a larger team.

23
O
C
T
2009

Pop quiz! Create an object of items and counts from a paragraph of text

I was digging around in some old code the other day, having a 'server' tidy up, and I came across a pair of code challenges that a company set for me a few years back. They were to try and gauge how you approach a problem, and see if you are at least familiar with the cfml code base. I quite like Ray Camden's Friday challenge idea, so in a blatant homage, I'm posing these two code challenges in the same way. This one this week, and a numeric one next week.

The challenge:

Take a paragraph of text and return a data object(whatever format you want) of the words in it, and their frequency. This is the example paragraph given.

view plain print about
1The old lady pulled her spectacles down and looked over them about the room;
2then she put them up and looked out under them. She seldom or never looked THROUGH
3them for so small a thing as a boy; they were her state pair, the pride of her heart,
4and were built for "style," not service -- she could have seen through a pair of
5stove-lids just as well.

The type of object and the method of producing it are entirely open. You an choose how to handle punctuation and text casing.

I've written a test form, and a solution myself, but it is always interesting to see how different minds approach the same problem.

I'll give it a while, and then post my solution here.

Update Here is a CFC that I put together to solve this. It strips out the punctuation, and creates a Structure of the words, and their count.

view plain print about
1<cfcomponent displayname="Parser" hint="Parses a set of text" output="false">
2
3    <cffunction name="parseText" hint="Parses a passed in section of text, returns a struct of values" access="public" output="true" returntype="Struct">
4        <cfargument name="rawString" required="true" hint="Text to parse">
5
6        <!--- list items to remove --->
7        <cfset var itemsToRemove = '-,;,",.'>
8        <cfset var parsedString = structNew()>

9        <cfset var part = "">

10
11        <!--- Clean the punctuation out of the arg --->
12        <cfset var cleanedString = ReplaceList(arguments.rawString, itemsToRemove, " ")>
13        <cfset cleanedString = lCase(Replace(cleanedString, ",", " ", "ALL"))>
14
15        <cfloop list="#cleanedString#" index="part" delimiters=" ">
16            <cfif NOT StructKeyExists(parsedString, "
#part#")>
17                <!--- Add to struct --->
18                <cfset parsedString[part] = 1>

19            <cfelse>
20                <!--- increment count, get it and add one --->
21                <cfset parsedString[part] = parsedString[part] + 1>
22            </cfif>
23        </cfloop>
24
25        <cfreturn parsedString />
26    </cffunction>
27
28</cfcomponent>

18
O
C
T
2009

Converting Word Press Cumulus plugin to BlogCFC

The other day I saw the Word Press Blog Cumulus plugin (http://wordpress.org/extend/plugins/wp-cumulus/) on a fellow bloggers site, and thought 'I like that, I wonder if it will work inside the Blog CFC framework'. I thought I'd convert it so that it would.

The Cumulus plugin uses the regular Blog category cloud and turns it into a three dimensional rotating globe. It does this using a flash object, and a series of parameters passed in as flashvars.

view plain print about
1<s/cript type="text/javascript" src="#application.rootURL#/includes/swfobject.js"></script>
2    <div id="flashcontent">This will be shown to users with no Flash or Javascript.</div>
3
4    <s/cript type="text/javascript">
5        var so = new SWFObject("#application.rootURL#/includes/tagcloud.swf", "tagcloud", "170", "120", "7", "##ffffff");
6        // uncomment next line to enable transparency
7        //so.addParam("wmode", "transparent");
8        so.addVariable("tcolor", "0x3258B8");
9        so.addVariable("mode", "tags");
10        so.addVariable("distr", "true");
11        so.addVariable("tspeed", "100");
12        so.addVariable("tagcloud", "#variables.tagsList#");
13        so.write("flashcontent");
14    </s/cript>

You need to include the 'swobjects.js' reference call to process to swf, otherwise the 'flashcontent' div will be displayed.

The flashvars include the variable 'tagcloud', this controls which tags are displayed, what their colors are, and where the go (URL). These are generated in a cfsavecontent variable almost as a list.

view plain print about
1<cfsavecontent variable="variables.tagsList"><tags><cfloop query="tags">
2                <cfif tags.tagCount EQ min>
3                    <cfset size="9">
4                <cfelseif tags.tagCount EQ max>
5                    <cfset size="20">
6                <cfelseif tags.tagCount GT (min + (distribution*2))>
7                    <cfset size="16">
8                <cfelseif tags.tagCount GT (min + distribution)>
9                    <cfset size="13">
10                <cfelse>
11                    <cfset size="11">
12                </cfif><a href='#application.rootURL#/index.cfm?mode=cat%26catid=#tags.categoryid#' style='#size#' <cfif len(variables.color)> color='0x#variables.color#' </cfif> <cfif len(variables.hicolor)> hicolor='0x#variables.hicolor#' </cfif> >#lcase(tags.tag)#</a></cfloop></tags></cfsavecontent>

The swf will control the color of the Tags based on their sizing, or you can specify a 'color' and a 'hicolor', which are the regular color and the highlight color respectively. I have placed the swfobject.js and the tagcloud.swf in my site/includes/ directory, but you can put it where you want, just edit the links.

You can download the code from RIA forge here: Link

Thanks to Roy Tanck for the documentation on how the Cumulus plugin works:

http://www.roytanck.com/2008/05/19/how-to-repurpose-my-tag-cloud-flash-movie/

_UNKNOWNTRANSLATION_ /