Why Coldfusion is my preferred development platform

I've been a professional web developer for just about a full year now, before that I was heavy into web consulting. I spent the last 5 years as a consultant, I got my start just before college. I love learning new technologies and playing with new tools, at my job my tool is Coldfusion. Here's why I love it. 

It's not like other languages
Java and PHP have their roots in C, from their syntax to how they look and behave, a C programmer wouldn't have much problem adapting to a language like java, nor would Java developers if they could understand pointers. There are many languages built that reflect the early days of programming with C such as operators like --, += ++ etc.. 

Coldfusion is unique, it's modeled after HTML. Coldfusion is simple yet complex, it's tag structure is familiar and powerful. It *feels* like HTML but its much more powerful. It's easy to learn and get started

Database integration is easy
It's really easy in Coldfusion to create a database query, all I need to do is call <cfquery> tell it what database to access, and give the query tag a name. Something like <cfquery datasource="myDatabase" name="MyQuery"> . Within the cfquery I can use regular SQL statements such as select, insert, update and delete. To access this datasource I just give my Coldfusion server access by using the admin tool and putting in the information. 

The really nice thing Coldfusion comes with is methods defined with the cfquery. For example if you wanted to return the size of the record set, just do myQueryName.RecordCount which returns the number of listings. Also, CFquery's have built in caching, just specify the time and Coldfusion will cache it for that amount of time, from 1 second to 1 year (or more!). This is a great feature if you need it. 

Queries are implicitly returned as a structure
This is the one thing I love about Coldfusion, it chooses the best way to store the data for you then it provides a really easy interface to access the data. So as in above, you do a cfquery with a name, then to iterate over that set, you just declare <cfloop query="myQuery">. From there just call a column defined in the cfquery. If you did a select * from a table with the column fullName you would simply call #fullName#.

Cross Site Scripting is a thing of the past
HTML is great, it's a wonderful tool, if used wisely. But HTML can become a dangerous tool to trick the user if used wisely, Cross Site Scripting is easily prevented by taking a variable and passing it into HTMLeditFormat() first. This escapes all HTML and makes it useless crap. 

Database security is easy
There are two wonderful things about Coldfusion and database security: CfqueryParam and CFC's. Let's start with CFC's. A CFC is a Coldfusion Component, I won't go into much detail (As it's noted in the next section) but they're designed to be an separation of data, business logic and presentation. CFC's are secure because you cannot access them in your browser, you can't even call them directly. But more on this later. CFqueryParam is the best thing since sliced bread. It makes SQL injection attacks a thing of the past and makes database security stupidly easy. 

A <cfqueryparam> takes two arguments, a type and a value. The type specifics what type of data is it expecting: an int, float, string, nvarchar, numeric etc.. the value is the variable. This makes it very secure, because before the server executes the query it validates the data, checking for things like blah' or '1=1' to protect from SQL injection. Easy, fast and simple. 

CFCs
Just after CFqueryParams in my list of amazing sliced bread awesomeness is the CFC. CFC's can contain everything from HTML to methods to queries… on and on. CFC's are best used for two things: separation of logic and OOP.

Separation of logic is very important, not only as a security concept but as a concept of working with programmers. A CFC can insulate your cfquery's from the outside world. CFC's have methods (Called: Cffunction) with access modifiers.

You can setup instance variables, create methods to query a database, process a file, upload a file, to send email-- Coldfusion can do it all. 

OOP. This concept is very sparse and not well defined in Coldfusion. But you can call a CFC, create an instance of that CFC and map specific pieces of data to that object. The Object only lives for as long as that page is used, once the page is gone, the Object is gone.

Coldfusion has the best books I've ever read
I hate reading dull books, by dull authors. I hate examples provided by most tech books to the point I've adopted the habit of just reading the manual and Googling a few questions I have. Coldfusion is different, the material online isn't there, however; Adobe has up it's sleeves: Ben Forta. 

He is the best author I've ever read, imagine reading a tech book and wanting to go on. It's almost like he's telling a story and you're part of that story. I've learned more about good software design in the first two books of the series: Adobe Coldfusion 8 Web Application Development then I've ever learned reading online or in another book.  

I've bought at least 3 "great/amazing" books on PHP, viewed many for Ruby and Java, I own a few of those too. No book or resource I have found has even come close to the quality of the information and ability to just go out and do cool stuff. Just try it for yourself, break, play have fun! It's a great read and a wonderful reference manual. 

It's not the end
While I loved Coldfusion and what it offers, I'm not sold on everything. Soon,x I'm going to document things I dislike and hate about Coldfusion and why it may not be the right tool for your job. 

 

Custom background images using Wordpress

Wordpress as a CMS

Wordpress is an excellent system to build your website, blog or even portfolio on. Almost all of my projects these days are for using Wordpress as a CMS. Not only can Wordpress do blogging very well, but it can also do content management really well. Today I'm going to introduce you to the custom field. 

The Custom Field 

The custom field has been around Wordpress since version 2. It allows you to customize posts & pages with content content that can exist in areas other then the primary post area. For example you can use it to display custom HTML in sidebars based on what page it is just by specifying the correct Custom Field name in your Post or Page. 

The Example 

A really good example of this is on a recent project I needed to have a unique background image with a default fallback image in place just incase we didn't set a new background image. There are many potential solutions to this problem: 

  • Set an ID of the div relative to the page ID value & create a custom CSS stylesheet with each background image
  • Setup a widget/sidebar area & insert a html style on the element 
  • Setup a widget/sidebar area & under lay an image & use z-index for positioning

Those would have been very complex, non-user friendly & hard to maintain; so I opted for the more user friendly experience: use Custom Fields. Custom fields are great because you can define anything you want or need within that field that is specific to just that page or blog post. But it provides you with a nice interface for managing content. 

The Code

It's really, really easy to get going on Custom Fields in Wordpress. In your page file all you need to do is define a name & then call it in your page or post. 

Here's an example of my code: 

<?php

// Showing the custom image defined on the page on admin 

if(get_post_meta($post->ID, "backgroundImage", true) != "") {

$format = 'style="background:url(%s);background-repeat:no-repeat;"';

printf($format,get_post_meta($post->ID, "backgroundImage", true));

}

?>

Let me break it down for you: 

  • Simple control structure to check for the existence of the get_post_meta data
  • The get_post_meta returns the data found with the page/post ID of argument backgroundImage, if nothing's found it returns a false & terminates the statement. 
  • $format is setting up a PHP format string, with the %s esentially a veriable we're going to use later
  • the printf calls the $format & the backgroundImage and formats it into a string

Doing this ensures that:

  1. I have a fall back for when something isn't defined. 
  2. I override any css by placing this as an inline style vs a css stylesheet style, ex <div //PHPstatement> </div> 
  3. The format string insures that I get the correct placement of the backgroundImage link every time the script is run when the page is built. 

Now to use this, all you need to go to is Post (Or Page) > Your page or Create New > Under the body of where you enter the content is a section for custom fields. Just plugin backgroundImages & the url, then you are golden! 

Resources