Luxury Yacht Vacations, Charter Marketing, Yacht Brokerage and New Construction

Sacks Yachts Magazine

Subscribe to Sacks Yachts Magazine: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Sacks Yachts Magazine: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Sacks Yachts Authors: Paresh Sagar, Steve Mordue, Jason Bloomberg

Related Topics: ColdFusion on Ulitzer, Java Developer Magazine

CFDJ: Article

And It Just Keeps Getting Better

And It Just Keeps Getting Better

I'm not talking about the obvious enhancements, things like:

  • Linux version
  • Native Solaris code
  • Service-level failover
  • Cisco LocalDirector integration
  • Server-side Java support

    Sure, those are all important and exciting. But amid all that excitement I fear some of the other really cool enhancements (ones that are immediately usable, ones that offer immediate value and benefit) are being overlooked.

    So, without downplaying the above-mentioned features, here is my own list of reasons to upgrade to CF4.5 immediately. Improved Variable Locking

    This is an important one. ColdFusion features several forms of persistent variables (see Table 1) ­ that is, variables that remain and retain their contents from one client request to the next. Persistent variables are important. They're about the only way to keep data (user information, shopping cart items, etc.) as users work their way through your site.

    But the use of persistent variables comes with a risk. Because ColdFusion is built on a multithreaded, multitasking engine, there's a real chance of multiple concurrent access attempts to the same data. If all you ever do is read this data, you'll probably never run into problems, but write access is a whole different ball game, and one that's likely to result in data corruption.

    To help address this problem, ColdFusion 4 introduced the <cflock> tag. Using <cflock> it's possible to prevent multiple concurrent access attempts by using code that looks something like this:

    <CFLOCK NAME="counter" TIMEOUT="10">
    <CFSET counter=counter+1>
    </CFLOCK>

    What's new in CF4.5 locking? Lots, starting with the fact that locking and unlocking of variables is a whole lot faster. In addition, you can now have ColdFusion automatically lock variable read operations (greatly simplifying your code, and preventing possible errors if you by mistake omit a lock, albeit with a performance trade-off). You can also have ColdFusion throw an exception if unlocked variable access occurs (this will help you find potential lock problems and fix them before any damage occurs). And finally, SESSION-variable access can be forced to be single-threaded so that variable access occurs sequentially (further eliminating potential locking problems).

    This is only the tip of the locking iceberg, and you should read the updated docs on <CFLOCK> for more information.

    CFMAIL Enhancements
    This is one we've all been begging for since the day <CFMAIL> was introduced: more control over outbound mail messages. CF4.5 has lots of new features here.

    First and foremost, <CFMAIL> now supports blind carbon copy using the new BCC attribute. (I suspect that this single enhancement will dramatically reduce Developer Forum postings!)

    Equally important is the addition of the new <CFMAILPARAM> tag. This tag has two uses: mail header manipulation and file attaching. Take a look at this code snippet:

    <CFMAIL FROM="#email_from#"
    TO="#email_to#"
    SUBJECT="Sales figures">
    <CFMAILPARAM NAME="x-priority" VALUE="1">
    <CFMAILPARAM FILE="c:\sales\jan.xls">
    <CFMAILPARAM FILE="c:\sales\feb.xls">
    <CFMAILPARAM FILE="c:\sales\mar.xls">

    Here are the latest sales figures.

    </CFMAIL>

    This outbound mail message uses four <CFMAILPARAM> tags. The first sets a custom message header; the others each attach a file to the message. It's as simple as that.

    Process Execution
    Several third-party tags are available that can be used to execute applications (or scripts) on your server. Not that there's anything wrong with those tags, but many users cringe at the thought of trusting application execution to unknown third-party code.

    Well, cringe no more. CF4.5 now features <CFEXECUTE> as part of the core language. This tag allows you to execute applications synchronously or asynchronously, and even allows you to capture the application output. Look at the following example:

    <CFEXECUTE NAME="C:\winnt\system32\ping.exe"
    ARGUMENTS="#ipaddress#"
    OUTPUTFILE="#temp_file#"
    TIMEOUT="30">

    This code executes the Windows NT-provided ping utility (used to check whether a specific host can be reached). The host address is specified in the ARGUMENTS attribute, and OUTPUTFILE specifies the name of the file to contain the ping output. If you were to read this file, you could use simple string (or RegEx) manipulation functions to check the results.

    Improved Debugging
    Debugging is something none of us ever want to do, but we end up doing it all the time anyway. So any help in the debugging department is greatly appreciated.

    CF4.5 has extended the debug output that gets appended to the end of your pages (if you don't know what I mean, turn on debugging in the ColdFusion Administrator and execute any page on your site). The new information (called "Detail View") provides detailed page execution with individual page components broken out individually. This one is guaranteed to help you pinpoint trouble spots, thereby improving your application's performance. Access to System Metrics

    Continuing with debugging enhancements, say Hello to the new GetMetricData() function (fast becoming one of my favorites). This function returns a structure containing system performance and activity information. Want to know how many requests are queued? Want to know average request and queue timings? Want to know how fast your database is performing? The function provides access to all that information and more, and all right from within your code.

    So what does that do for you? Consider the following. How about intelligently serving live database results if database server activity is low, and serving cached results if the database server is backlogged? Or how about redirection to cached copies of pages if too many requests are queued?

    You get the idea. Self-optimizing code ­ the possibilities are mind boggling.

    New Functions
    As with every release of CF to date, CF4.5 introduces several new functions (10 of them this time). Included in these are several data conversion functions, the GetMetricData() function I just mentioned, a function that returns a list of all available functions (I'm still trying to find the killer app for this one) and the URLDecode() function.

    This last is one I personally have been begging for for years. URLDecode() is the opposite of URLEncodedFormat(); it takes a string that has been URL-encoded and simply decodes it. So why is this so exciting?

    For me personally it solves a problem I've been working around for a long time ­ and it's not a CF problem. It's an HTML limitation problem. If you've ever tried passing hidden form fields from one page to the next, you'll sympathize with me. HTML form fields have a horrid little limitation ­ they don't like embedded double quotes (browsers treat these as end-of-field designators). In the past the workaround was to replace the double quotes with other characters or strip them out altogether, neither of which is an ideal solution. The obvious solution was to use URLEncodedFormat() to encode the string (any double quotes would be replaced with %22, which is perfectly safe in a form field), but decoding that string was problematic as CF had no function that did the opposite of URLEncodedFormat(). Not anymore. (Now I need to find time to go back and clean up all that old ugly code.)

    White Space Suppression
    Okay, those of you who know me know I don't think extraneous white space is a big deal. But judging by the audience reaction when I announced this feature at the User Conference, I must be in the minority here. So here it is.

    CF4.5 has added the ability to automatically strip out much of the extraneous white space that used to show up in the generated page output (you know what I mean ­ all those blank lines you saw when you did a View Source in your browser). You can even turn on a server-wide setting that will automatically perform this suppression for all requested pages served by the server. It's safe, it won't break anything and it will reduce your generated page size slightly.

    Conclusion
    So there you have it ­ my list of reasons to upgrade to CF4.5 immediately. If your own list is different, I'd love to hear from you.

    The bottom line is that I'm very excited about ColdFusion 4.5. While I don't believe the changes are significant enough to warrant a new book (sorry, had to drop that in there; I get asked about that almost every day), I think you'll find that this new release will make your life just that much easier. And considering how much time we spend at the keyboard, that's a good thing indeed.

  • More Stories By Ben Forta

    Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.