CFML differences between Railo and ColdFusion 9/10 (Part 2)

by kai on 18/02/2013



Yeah, so much for “I’ll post part 2 tomorrow…“. Sorry guys, life and work got kind of in the way. Here’s part 2 now though :)

4. Date comparison

If you use if constructs for string comparison in ColdFusion, the server will always check if a string on either side of your if-condition could potentially be a date value in a string. Railo uses a different approach and will only check for this if at compile time there’s a date value (for example from a query column) on at least one side of the comparison. This obviously saves a lot of very expensive string comparisons at runtime.

If you want to explicitly check for dates in a comparison, you should use parseDateTime():

<cfif parseDateTime(strDate) EQ parseDateTime("01.01.13")>

5. More date stuff: Date parsing

Adobe ColdFusion allows implicit parsing in locale formats. Something along the lines of:

<cfif now() EQ "Wednesday, January 30, 2013 4:02:12 AM NZDT">

In Railo you can’t do this and you’d have to use parseDateTime() again (see above). The reason is: Parsing reasonably complex strings is a noticeable performance overhead and the Railo team has decided not to support this approach.

<cfif now() EQ ParseDateTime("Wednesday, January 30, 2013 4:02:12 AM NZDT")>

6. Passing-by-value vs. passing-by-reference

You might know that if you’re passing complex datatypes such as Arrays and Structures around and assign them to new variables, Adobe ColdFusion would always pass Arrays by value but all other complex datatypes by references (i.e. as a pointer). That’s not new and I think everyone has probably realised this by now.

There’s a funny inconsistency though: If you pass an Array as an argument into one of your own custom functions, the Array is passed by value (as I’ve described above). However, if you pass an Array into various Built-In-Functions in Adobe ColdFusion, it’s being passed in by reference.

Take for instance ArrayAppend(array_to_append_to,value). Clearly the array_to_append_to value I’m passing into my function is passed in by reference here.

Railo is treating this scenario differently. In Railo, all variables of complex type are passed into functions (both Built-In and one’s own) as references. That provides consistency and it might actually even give you a tiny performance gain.

If you wanted to have an Array passed into your function by value (as Adobe ColdFusion would do), you can specify a passby-attribute for the argument:

<cfargument name="x" type="array" passby="value">

Wrap-up

There you go, some more differences between Adobe ColdFusion and Railo. Let’s hope I’ll get part 3 out of the door really soon :) On the list for part 3: Differences in managing and dealing with nested struct keys and some more goodies.

{ 5 comments… read them below or add one }

Leave a Comment

{ 1 trackback }

Previous post:

Next post: