CFWheels – Rediscovering beauty in CF Code

I haven’t been blogging much of late. Lots of traveling and work kept me away.

During this time, however, I have somehow managed to find time to play with Wheels. And I must say it has been a pleasure working with it.

I’ve dabbled with Ruby on Rails and Grails in the past and have always lamented about the fact that the frameworks in CF do not possess the same beauty and elegance.

Well, CFWheels changes all that.

If you ask me, I’d say that all CF developers should at least try it out to once to see all that it has to offer.

Personally, I like they way the MVC architecture is implemented in CFWheels — pretty much like Rails/Grails. Plus domain modeling and  URL rewriting using routes — leading to very nice, readable URL. And not to mention time-saver features like view helpers that let you build nice views and forms and add validation to them. And also the plugins… And also the provision for different environment like design/development/test/production.

I’ve tried it on Railo and it is blazing fast. I’m sure it would be as quick on CF9.

I could go on and on. But it is simpler for you to simply head over CFWheels to discover the magic.

Case-sensitive assertEquals Assertion in MXUnit

If you use the MXUnit testing framework for ColdFusion, you might have come across this earlier — the assertEquals assertion is case-insensitive.

This means that if you try and compare a string like ‘abs’ and ‘Abs’, assertEquals returns true.

And that is ok in certain cases, but is not ok in many other. I guess it boils down to the fact that at the end of the day, ColdFusion is case-insensitive. A variable called ‘firstName’ is the treated the same as ‘FirstName’.

But enough of that.

So how do you test for case-sensitivity in assertEquals assertion?

First I thought I’d write my own assertion. But then there is a much simpler solution. Simply hash the the two strings that one needs to compare and assert that they are NOT equal.

So rather than:

assertEquals("abs", "Abs")

Use

assertNotEquals(hash("abs"), hash("Abs"))

It works quite nicely.

Do you do it differently?

BTW, there some discussion of this on the MXUnit Google Groups as well.

Storing different content in a Git branch

If you are used to the Subversion way of doing things, branches tend to have more or less the same content/code, obviously with a few changes as the development progresses.

But in Git one can store content that is completely different from the content in a branch.

Now you might wonder why one would want to do that. But I guess there are some reasons for it. For example, I believe the Git repository itself has a TODO branch that allows developers to keep notes on what needs to be done in the future, but does not contain code. That way notes are versioned as well.

The thing about Git is that it allows for easy setup of such not-ordinary uses of a version control system — I think that is what gives it “more legs” over other DVCSs. And why one should look at using Git over other DVCS systems.

Have a look at this screencast that takes one through how to create such branches — also referred to as “empty branches” because one creates an empty branch, and then fills it with other content that does not relate to the master branch.

But if you want to create a branch like that, you can use the following code that I found buried in one of the comments on the screencast.

git symbolic-ref HEAD refs/heads/newbranch
rm .git/index
git clean -fdx
<<<< do your work >>>>
git add your files
git commit -m 'Initial commit'

Just gotta love Git.

Using Decentralized Version Control with CF – My talk at CFObjective ANZ

A couple of weeks back I presented at CFObjective ANZ in Melbourne, on how to make ColdFusion development a little more cooler using a decentralized version control system (DVCS) like Git.

The basic idea behind the presentation was this:

A commonly used version control system in the ColdFusion community is Subversion — a centralized system that relies on being connected to a central server. The next generation version control systems are decentralized, in that version control tasks do not rely on a central server.

Decentralized version control systems are more efficient and offer a more practical way of software development.

In this session, I covered considerations in moving from Subversion to Git, a decentralized version control system. And also the pros and cons of each.

Version control is often used in conjunction with a testing framework and continuous integration. I wanted to demo an example of how to integrate Git with a testing framework, MXUnit, and a continuous integration server, Hudson. But ran out of time. So maybe that is something I can do another time in another conference!

You can download a PDF it here: Make it Cooler – Using Decentralized Version Control

Or view it at SlideShare.

Would like to hear from you on what you think of it.

Apache Rewrites for Subfolder Install of CFWheels

By default the CFWheels framework and application is installed in the webroot.

But if you want to install it in a subfolder in the webroot, you need to change the rewrites slightly.

I use the following and it works quite well.

In the example below, I have a server called hello.cfwheels.local, and it points to a folder under the webroot called hello.

ServerName hello.cfwheels.local

RewriteEngine On
RewriteOptions Inherit

RewriteCond %{REQUEST_URI} ^.*/(flashservices|flex2gateway|railo-context|robots.txt)($|/.*$) [NC]
RewriteRule ^(.*)$ http://127.0.0.1:8080/$1 [P,L]

RewriteCond %{REQUEST_URI} ^.*/(files|images|javascripts|miscellaneous|stylesheets|plugins|sitemap.xml|rewrite.cfm)($|/.*$) [NC]
RewriteRule ^(.*)$ http://127.0.0.1:8080/hello$1 [P,L]

RewriteRule ^(.*)$ http://127.0.0.1:8080/hello/rewrite.cfm$1 [P,L]

RewriteRule ^/(.*)$ http://127.0.0.1:8080/hello/rewrite.cfm/$1 [P,L]
ProxyPassReverse / http://127.0.0.1:8080/hello/rewrite.cfm/

ProxyPreserveHost on

If you think there is a better way to accomplish this, please drop in a line.