Web DevCenter
oreilly.comSafari Books Online.Conferences.
MySQL Conference and Expo April 14-17, 2008, Santa Clara, CA

Sponsored Developer Resources

Web Columns
Adobe GoLive
Essential JavaScript
Megnut

Web Topics
All Articles
Browsers
ColdFusion
CSS
Database
Flash
Graphics
HTML/XHTML/DHTML
Scripting Languages
Tools
Weblogs

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed

Learning Lab






ColdFusion MX on Mac OS X, Part 1

by Dick Applebaum
06/21/2002

Editor's note--In this series of articles, Dick Applebaum discusses the evolution of ColdFusion MX, one of the hottest new Web development products, and how to get ColdFusion MX running on Mac OS X.

What is ColdFusion?

ColdFusion is a system for rapidly developing and deploying Web sites, particularly those that involve interaction with databases and the presentation of dynamic results.

In a few short years, ColdFusion has become one of the major players in the highly competitive environment of hosting and delivery (serving) of Web applications. There are many reasons for the popularity of ColdFusion, but I'd like to focus on those that I think are most important from a Web developer's point of view.

A Little Personal Background

I've been developing Web sites since 1997. I use programming to give the sites capability beyond serving static HTML pages. Like many others, I began with Perl CGI programming and even wrote a few Perl shopping carts, for my own amusement. Sometimes, a client needed some modifications to existing programs, so I also wrote some ASP and hybrid applications.

In those days, I had a slow modem line, so I was very aware of bandwidth and performance, especially the perceived performance that confronts the typical visitor to one of my clients' sites. To this end, I would often use client-side techniques such as frames, JavaScript, DHTML, and (later) Flash to improve the user experience.

Drill-Down and Dynamic Data

At the server, I would design my programs so they would efficiently deliver pages in smaller, more digestible chunks.

For example, one site displayed news articles. We could have designed it to retrieve hundreds of long articles then download them for display on the browser. This would probably take several minutes and the user would likely get bored and move to a friendlier, more responsive site.

Instead, we retrieved and downloaded the title, author, and a short abstract of the top ten news articles. This only took a few seconds! The user could click on a specific article to retrieve and display the complete text in a pop-up window (another few seconds). Alternately, the user could browse through the next (or previous) ten articles or jump to the first, last, or intermediate groups of ten. Each browse action initiated another request to the server for another group of ten article abstracts.

Related Reading

Dreamweaver MX: The Missing Manual
By David Sawyer McFarland

A third option was to search the articles for such things as keywords, authors, source, and so on, to display a list of articles and abstracts that matched the search criteria. As above, the user could navigate through the matched articles in groups of ten.

With this approach, called drill-down, the user can quickly and easily browse large amounts of data and focus on the specific information desired. The user experience is an interactive "Click and Go" rather than "Click and Wait".

You might say: "I've seen lots of sites that work this way". That's the point. It's a pretty good way to design a Web site. It doesn't overload the server, the communication lines, the browser, or the user with volumes of unnecessary information. But, as we'll see, this requires extra design and programming effort.

To support this interactive user experience, some work needs to be done in the programs that run server-side. We must:

  • Retrieve the requested information from a database.

  • Cache the information on the server so it can be efficiently browsed.

  • Remember where each user is and what he is doing (what page he or she is on)--in other words, maintain the state of each user.

  • Divide the information into digestible chunks that can be efficiently and quickly downloaded and displayed on the user's browser.

  • Allow the user to navigate through the chunks of information presented (First, Last, Next, Prev, Specific Page, and so on).

Most of the early Web programming languages do little or nothing to assist the developer with these requirements. Many languages do not even support databases without first installing add-on components. So you end up having to do all the work yourself in each and every program that uses drill-down or dynamic data.

Enter ColdFusion

From its inception, ColdFusion (CF) was designed to integrate database with Web presentation. CF hides a lot of the messy details of interfacing a database. You don't need to devote your valuable developer time to understanding and programming these details. CF does that for you. Instead you focus your attention on the needs of the application. Here are a few ColdFusion benefits for our drill-down example:

  • With a single command (cfquery), CF will query a database and store the results in an array.

  • An option to the cfquery tag causes the query results to be cached in memory so you can reference the data multiple times without "Maytagging" the db server. Author's note: Early disk drives from IBM were the size and weight of a washing machine. When put under heavy load, the rapid movement of the seek arm would cause the drive to vibrate and literally "Dance" across the floor, resembling the Maytag wash machines of the 1930s.

  • CF provides a simple, yet powerful, mechanism for maintaining the state of each visitor to the site. You keep track using a unique set of "Session" variables for each visitor. Each visitor (and the associated "Session Variables:" is tied to a cookie or a token (provided by CF) that gets passed with each page.

  • Once the data is retrieved and cached, it's broken into digestible chunks (say groups of ten). Another CF tag makes it easy to iterate over the array (created by the cfquery) and extract only those items requested for presentation (as defined by the visitor's Session variables").

  • Paging through the information is just a re-execution of the iteration process with a different starting point for the next (or other) group of ten.

All these things are built into ColdFusion and designed to work together. They make it easy to accomplish drill-down presentation of dynamic data. So, from a developer's point of view, it's much easier to write complex programs with ColdFusion than with other programming languages.

Application Program Maintenance

The Web changes rapidly, and the sites that don't keep up with the changes will likely languish. An often-ignored part of Web development is the cost of maintaining a Web application over time -- usually by several different people.

ColdFusion programming uses English-language tags such as cfQuery, cfFile, cfMail, and so on. These are easy to read and understand. CF Programs also tend to be self-documenting. This means that anyone who knows ColdFusion can look at the program, understand what's going on, and even modify it. Sites implemented in ColdFusion can realize significant savings in program maintenance costs over the life of the application.

Prototyping and Rapid Development

When a developer interacts with a potential client, the client may have only a general idea of what he or she wants from the Web site. The power and compactness of the CF language make it ideal for quickly prototyping the "look and feel" of the site to show to the client. Using CF, the developer can easily:

  • Design, create, and populate prototype databases if none exist.

  • Interface, extract, and manipulate existing legacy databases to build prototype versions.

  • Build dynamic-content Web pages using drill-down or other techniques.

It's a simple matter to put together such a prototype, deploy it, then demonstrate it in the client's office, or even over the phone. So, from a developer's point of view, CF helps to determine the clients' needs and demonstrate a prototype solution without investing a lot of time and dollars. And you, as the potential developer, get to "Strut your stuff".

The Macro Power of ColdFusion

ColdFusion has a full complement of powerful tags and built-in functions that make it easy to tackle almost any Web-programming task. By this, I don't mean that you can write macros with CF; rather, that the ColdFusion tags and functions themselves are powerful macros. To illustrate the significance of this, here's an example:

When I first became aware of ColdFusion, I wanted to test its capability by writing a "Real Application". I had recently completed a Perl shopping cart program that was about 100K of liberally commented code.

I copied this into a blank ColdFusion template (program file). Then, I went through the program routine by routine, analyzing the Perl statements and converting them to CF statements that give the same results. As I'd convert a group of statements, I'd comment out the Perl and include the CF tags intermingled with the comments.

After several hours of this, and some testing, I had an operational CF program with hundreds of lines of "Perl comments." I zapped the "Perl comments" and I had a CF program that was smaller, ran faster, and was easier to understand than the Perl original. I was amazed how easy it was to replace lines of Perl statements with fewer, more powerful, CF tags.

Consider a little routine to calculate a cookie expiration date, seven days after today's date. It's not as simple as it sounds. You must take into consideration month-end, year-end, leap year, and so on. This took about 30 lines of somewhat cryptic Perl code. In CF the replacement one-liner reads:

<cfset newdate = DateAdd('D', 7, Now())>

All in all, I was able to throw away 75 percent of the Perl code.

In this case, macro programming means replacing one for many. This is truly a power feature that sets CF apart from other Web programming languages. With CF, developers can be more productive, competitive, and profitable!

Pages: 1, 2

Next Pagearrow