Thursday, January 31, 2008

Should we extend CF Objects with java APIs?

There have been a couple of recent posts regarding extending ColdFusion data types using the underlying java APIs.

ColdFusion array is actually an implementation of java list (java.util.List). So all the list methods are actually available for Array. CF provides most of the list functionality using Array functions but there are few things possible with java list which you can not do directly with CF functions.

For example, you can use java API to search an array to determine the position of a given search criteria.

<cfset myArray = listToArray('vanilla,chocolate,strawberry') />
<cfif
myArray.contains('strawberry')>
<cfset
strawberryIndex = myArray.indexof('strawberry') + 1 />
</cfif>
<cfoutput>
#myArray[strawberryIndex]#</cfoutput>

Note the adjustment that I've made to account for java arrays starting at 0. Russ Johnson, Rupesh Kumar and Adrian Moreno go into how to do this in more detail.

It's really quite cool that we can do this sort of thing, but should we? One of the great strengths of ColdFusion is its backwards compatibility. I have code, written for ColdFusion 4.5, that's been running untouched for 6 or 7 years. For those keeping count that's about 5 major releases ago. Adobe/Macromedia/Allaire has been great over the years about letting us know what's changed with various versions of ColdFusion. What happens if a future version of ColdFusion ends up breaking this functionality? We certainly can't expect Adobe to keep us informed when one of their changes breaks undocumented features of the product.

Perhaps it's because I'm in the middle of planning a ColdFusion 8 migration, but for my money maintainability nine times out of ten outweighs the short term gain of using these features. That's not to say that I'll never use this knowledge, but that I'll think very carefully about the possible consequences and benefits before doing so.

Labels: , ,

posted by Luis

0 Comments:

Post a Comment

<< Home

Template design by MLP Design
Licensed under CC-NC 3.0