ColdFusion: My First Impressions

Adobe ColdFusion

After working with Adobe ColdFusion for about a month now, I have to say that I’m really impressed.  I had this expectation that it would leave me longing for my beloved PHP.  It’s actually a very cool server side language that allows for insanely fast development of dynamic web applications!  I know, I sound like a commercial…so, let’s start with the negatives of ColdFusion just so you know I’m not getting paid by Adobe or something!

First, ColdFusion is very proprietary.  In order to use it, the web server must have Adobe’s ColdFusion Server software installed and running.  That software isn’t free.  Many web hosts don’t bother with it for this reason…why pay for ColdFusion when PHP is free?  I get that…there is an open source alternative called Railo and it is pretty good too!  Unfortunately, trying to convince your web host to install this is a different story!

The next negative aspect of ColdFusion is that it is overly simplified. For example, there is only one loop tag. CFLOOP is your only option! There are different parameters to set what kind of loop it is, but this causes confusion when reading over someone else’s code. In PHP it is always very clear what kind of loop I’m looking at. If it’s a while loop, it says ‘while’.

So, the CFLOOP tag was supposed to make things easier. You only need to remember one LOOP tag and then just set the parameters for the loop to determine what kind of loop it will be.

Now, what I LOVE about ColdFusion how elegantly it interacts with SQL databases!  So much can be done with very little code and that makes for insanely fast development!  Let’s look at a comparison of a simple SQL query with some output in both PHP and ColdFusion.  First, in PHP:

<?php
  //connect to db
  mysql_connect("localhost","username","password") or die ("Failed to connect to mysql");
  mysql_select_db("databaseName") or die ("database not found!");

  //check url for id variable
  if (isset($_GET['id'])){
    $id = $_GET['id];
    $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
    while($row = mysql_fetch_array($sql)){
        $product_name = $row["product_name"];
        $product_details = $row["product_details"];
        $product_price = $row["product_price"];
    }
  }else{
    echo "No product was selected!";
    exit();
  }

  mysql_close();

  //dynamic output
  $output = '
                 <table>
                   <tr>
                     <th>Product Name</th>
                     <th>Product Details</th>
                     <th>Product Price</th>
                   </tr>
                   <tr>
                     <td>' . $product_name . '</td>
                     <td>' . $product_details . '</td>
                     <td>' . $product_price . '</td>
                   </tr>
                 </table>';
?>

<html>
<body>
<?php echo $output; ?>
</body>
</html>

Next, let’s look at the exact same thing done in ColdFusion:

<!---Check url for id variable--->
<cfif isDefined url.id>
  <cfquery name="products" datasource="store">
    SELECT *
    FROM products
    WHERE id = '#url.id#'
    LIMIT 1
  </cfquery>
<cfelse>
  <cfoutput>No Product Was Selected!</cfoutput>
  <cfabort>
</cfif>

<!---Dynamic Output--->
<html>
<body>
  <table>
    <tr>
      <th>Product Name</th>
      <th>Product Details</th>
      <th>Product Price</th>
    </tr>
    <tr>
      <cfoutput query="products">
        <td>#product_name#</td>
        <td>#product_details#</td>
        <td>#product_price#</td>
      </cfoutput>
    </tr>
  </table>
</body>
</html>

The ColdFusion took me half as much time to write as the PHP and it works just as well.  So, overall, I am very impressed with ColdFusion.  A lot of my web developer friends talk crap about ColdFusion, and that’s okay…Most of them have never actually developed with it, so I take those opinions with a giant grain of salt!

Keep on the lookout for some ColdFusion Tutorials in the near future!

About Tom Duffy

Tom Duffy Owner - Tech Remedy Owner - Host Remedy Development and Linux geek

3 thoughts on “ColdFusion: My First Impressions

  1. Tom, welcome to the wonderful word of ColdFusion. It rocks!

    I have been developing web applications in ColdFusion for about a decade now, and there are few things I haven’t been able to accomplish very gracefully with ColdFusion. In my humble opinion, it is about the best platform there is for developing web applications.

    - Cheers!