Top 10 Underrated Functions in ColdFusion

January 10, 2007
coldfusion

I gave a presentation at my local CFUG yesterday called 10 Underrated Functions in ColdFusion, I plan on doing one for tags as well at some point. Here was my list of functions, in no particular order:

  • ValueList - Returns the contents of an entire query column in a string list.
  • ExpandPath - Returns a server file path relative to the calling template.
  • Hash - Encodes a string using MD5, or in CFMX 7 you can specify any hashing algorithm such as SHA.
  • RandRange - Returns a random number bound by two integers.
  • XmlFormat - Escapes special characters in XML, and can also be used to prevent cross site scripting attacks.
  • IsValid - Validates that a string is in the specified format (email, ssn, integer, etc).
  • GetMetricData - Gives server metrics, like average request time, etc.
  • ToScript - Serializes a ColdFusion variable into JavaScript or ActionScript
  • GetPageContext - Gets the JSP PageContext object. Can be used to include JSP files in a CFM page, and more.
  • XmlSearch - Search an XML document using an XPath Query

Did I have any obvious omissions? What would be on your list?



Related Entries

This entry was:

Comments

There are a LOT of functions that I think are underrated - in fact, I think all built-in functions are overlooked at one point or another. I honestly have been meaning to re-read the function reference to remind myself of some of the gems out there.
I'm always amazed whenever I see someone manually implement code to do what listQulify() or listChangeDelims() does.
IsValid() is one of the best functions ever
A few: incrementValue/decrementValue: If you don't need to keep the result, this is handy in urls, for example, linking ot the next page. isDebugMode - add your own debug stuff (I need to blog this) A big amen on isValid. I think it is probably the least known cool feature of CF7.
ArrayToList() and ListToArray() would have to be one that I see implemented in other ways frequently.
Brian - what about manual implementations of fileExists() or directoryExists()? I'm guilty of those (a long time ago ;)
"I'm always amazed whenever I see someone manually implement code to do what listQulify() or listChangeDelims() does." I'm even more amazed that I still do it from time to time =)
Forgot to subscribe.
They may not be under-rated but I find that val() and htmleditformat() are often overlooked in securing templates from incoming POST/GET data.
I'm with Brian on ListQualify. That's a hidden gem from 4.01 that it seems many missed (and continue to do). Great list, Pete. Thanks for sharing.
What about urlEncodedFormat() and urlDecode() - I've seen manual workarounds to these before.
Mine would probably be monthAsString in combination with setLocale(), coming from the Netherlands (in other words a non-english speaking/reading country) i still see a lot of developers making a list with the locale names of the months and then a loop with 1 to 12 and getting the correct name :-) monthAsString(month(now())) would do the trick.. also for days. Much overlooked function. LSDateFormat(now(),'mmmm') would also do it.
XmlFormat() is kinda the suck, it does not parse xml all the time correct. I know its sloppy but I have been to busy to combine the 2 udf's but these in tandem will format anything in xml http://www.cflib.org/udf.cfm?ID=999 and http://www.cflib.org/udf.cfm?ID=572
Oliver, I'd love to see an example of where XmlFormat doesn't work. I haven't had any problems with it, not to say there aren't - I'd just like to see first hand.
Just to go along with value list, there's the little used QuotedValueList() which does the same thing as ValueList() but puts quotes around each list item (like ListQualify() with quotes).
xmlFormat is VERY broken. I've had numerous issues with it on BlogCFC where xmlFormat would let characters by (like MS Extended chars) that mess up valid XML.
Here is a link to a corrupt xml product feed, that used xmlFormat(). http://www.mothernature.com/xmlFormat_blows.xml. I will leave that example up for a week. I had to use the udfs above xmlFormat2(xmlsafe()), lazy I know but it works.

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?