Daryl's ColdFusion Primer

[<--Prev] [Next-->]
[Printable Version] [Search: ] [Daryl's TCP/IP Primer] [Daryl's ColdFusion Blog]
ColdFusion Slow?  Find out why with SeeFusion

2. Introduction

What is ColdFusion?

Dynamic Web Pages

ColdFusion is a programming language. Like Java, in the sense that it is nothing by itself; it requires a programmer with vision and skill to make anything useful out of it. Like Visual Basic, in the sense that the language is tailored for a specific purpose, but general enough to accomplish most any task easily within that scope. (Visual Basic is designed to make applications for the Windows environment; ColdFusion is designed to make applications for the Web server environment.)

Databases

ColdFusion was originally designed for allowing database contents to be easily displayed in Web pages for any browser, without plugins, by manipulating the HTML output of a Web browser. Since the browser is fed nothing other than standard HTML, no plugins are needed.

More..!

ColdFusion also makes gathering, manipulating, and presenting data from other data sources easy, including other Web servers, FTP servers, ASCII data files, POP mail servers--not even COM and CORBA objects are safe :-)

Programming for the Web

Procedural and OOP Run-Time Environments

Most programmers are used to working with procedural or object-oriented (oop) languages like Pascal, C++, and Java. The "run-time" environments for these languages are similar: you start an application, the application runs, and then the user quits the application. A continuous "state" is created at startup, maintained throughout the operation of the program, and destroyed (or saved) at program shutdown.

The ColdFusion Run-Time Environment

A ColdFusion template (think "program" or "program module") is processed when a request is made to the Web server. Once the template has completely finished processing, the Web server sends the HTML generated by the template. (Not even one byte of output is sent to the browser until the template has completely finished.) During a template's execution span, it may prepare and send several SQL statements to be processed by ODBC database systems, or prepare and send HTTP requests to other Web servers, or do whatever else is necessary to acquire and format data for the end user.

Uh, What Language Again?

Multiple-Language Environment

ColdFusion's primary strength is its ability to actively "glue" systems together. Sometimes dynamically writing SQL statements, sometimes gathering related data from other systems, and sometimes altering or outright writing JavaScript statements to be sent to the client browser, ColdFusion acts as middleman and traffic cop. Because you can be working with four or more programming languages in the same template (I'm counting SQL and HTML as "programming languages" here, though that's being generous,) it's extremely important to remember which language you're working with at any given time, especially since you'll often find ColdFusion expressions or tags embedded in any of them.

ColdFusion

ColdFusion is designed to be embedded in other languages--most notably HTML. It is designed like HTML; most of its major capabilities are accessed through tags. Just as <TABLE> and </TABLE> mark the beginning and end of an HTML table, <CFQUERY> and </CFQUERY> mark the beginning and end of an SQL query in ColdFusion.

SQL

SQL is designed to easily and conversationally retrieve and manipulate data stored in any form of relational database (or manipulate the databases themselves, but I'm not going into that in this Primer.) SQL statements are executed outside of ColdFusion; once the </CFQUERY> tag is reached, the SQL generated within the <CFQUERY> tag is sent to the SQL database engine (Access, Oracle, NonStop SQL, or whatever.) The ColdFusion server waits for all of the results to be returned, then resumes processing of the template.

Someone once asked me which is faster, a ColdFusion database or an Oracle database. The question was nonsensical. (What coffee tastes better: Maxwell House or Mr. Coffee?) I was reminded of the Dilbert comic where Dilbert's boss asked him to build a database. Dilbert was fairly sure his boss didn't understand what he was talking about, so he asked his boss what color he wanted that database. 'I think Mauve has the most RAM...'

*

At the risk of being redundant, ColdFusion is not a database system. ColdFusion is an applications development language tailored toward presenting data retrieved from SQL data sources in HTML format.

JavaScript

JavaScript is designed to make a browser a complete programming environment; unfortunately, due to severe compatibility problems from browser to browser, its practical use seems (in my humble opinion) limited to basic forms automation. Since some people turn JavaScript off in their browsers, or run browsers that don't support JavaScript at all, I try to restrict my JavaScript to non-critical features. On internal systems with a predictable browser set (such as company intranets) I will use more JavaScript.

Java?

About the only things JavaScript and Java have in common are the name, and some basic syntactic elements. I generally try to avoid Java applets in Internet systems; they often take way to long to load, their window size is static, and most of the features you'd use an applet for can be implemented in a simple, standard, HTML-based manner. When graphing is required, however, you will often find me using ColdFusion to write parameters for the KavaChart applets, available at http://www.ve.com/.

When and Where

It's also critically important to keep in mind when and where these languages are executing:

  1. A browser submits a form, possibly triggering JavaScript event handlers.
  2. The web server reads the requested template and passes it off to the ColdFusion Application Server service for processing.
  3. The template is scanned for ColdFusion tags and expressions, which are executed in the order coded.
  4. If any ColdFusion tag is encountered that operates with external data, such as <CFQUERY>...</CFQUERY> or <CFFTP Action="Get">, the external server is accessed and the data retrieved before the next ColdFusion statement or expression is evaluated.
  5. Once the ColdFusion server is finished processing the template, the resulting HTML (and JavaScript, as applicable) is sent to the browser.
  6. The browser reads the HTML and renders the page for the screen, executing any "inline" JavaScript statements embedded in the file.
  7. As the user, uh, uses the forms on the page presented, any applicable JavaScript event handlers are triggered. These event handlers may validate input, alter form contents, or even change the destination of the form, all without bothering the web server.
* It is very easy to forget which language you're coding in from one line to the next. One of the biggest hurdles novice ColdFusion programmers have to overcome is remembering where, and when, code from various languages is run. For example, you cannot change the processing of the ColdFusion portion of a given page using JavaScript, because the JavaScript is not processed until after all of the ColdFusion code has been processed, and the Web server has sent the resulting HTML to the browser.


Next: ColdFusion Foundations
Copyright ©2000-2017 Daryl Banttari. See [Disclaimer]. [About Daryl]