DEV Community

Michael Born
Michael Born

Posted on • Originally published at michaelborn.me

Why I Program in Coldfusion

I get asked this a bunch. Why are you programming in Coldfusion, anyway? Isn't Coldfusion dead? Isn't it closed-source? Isn't it expensive?

  1. Nope, Coldfusion is not dead.
  2. Nope, I use and prefer Lucee, the open-source Coldfusion engine.
  3. Nope, not expensive. (See above.) Lucee is free! (as in beer.)

In two words, I use Coldfusion because it is Easy, and it is Powerful.

What is Coldfusion?

What the heck is Coldfusion, anyway? Coldfusion is a programming language which runs on the Java Virtual Machine (JVM), which means that it compiles to Java and can run anywhere Java can. (Windows, Mac, and Linux.) Coldfusion is cool because it has many high-level tools baked in which make it super easy to get stuff done. You can index and search documents or web pages, create spreadsheets and PDFs, connect to a server via IMAP or POP or FTP or LDAP - there's just a TON baked right into the language with zero library or extension headaches to install.

When most folks think of Coldfusion, they think of the version they used in '05 with <cfdiv> and <cftable> and all that good stuff. Be serious. That legacy junk has been frowned upon for a long time. The real Coldfusion is a JS-like syntax with full object-oriented functionality coming straight from Java - final and static functions, accessors, etc - and functional programming features such as threading, async and locking. To me, that's what Coldfusion really is.

Coldfusion is Super Easy

Can anyone tell me what this is?

var ducks = [{name: "Donald"},{name: "Daffy"}];
var names = [];
for( var duck in ducks ) {
    names.append( duck.name );
}

Nope, not Javascript - that's Coldfusion's script syntax. If you're familiar with JS you should be able to pick up Coldfusion no problem.

There's also a totally different syntax which closely mirrors the HTML markup style. For devs who know HTML but don't know JS (likely a shrinking crowd), you have at least the option of getting started with that markup syntax. This alone makes it very easy for new devs to get started with CF - Hamilton College mentioned this psychology of onboarding new devs, and it evidently worked - the new college website won a Webby award last year.

Coldfusion is Super Powerful

I built a website for a painter several years ago using PHP and Bolt CMS. One additional request the client had was to embed a watermark into every image served on the website. Try as I might, I could not get this done within the client's minimal budget - PHP's image processing functionality is somewhat minimal without addon extensions such as GD.

In CF, there is a single function which allows this: imagePaste(). Take a watermark image and paste it onto a second image, in the upper left corner. Write the image to a file. Done.

var watermark = imageRead( "images/myBrand.jpg" );
var thePhoto = imageRead( "images/upload.jpg" );
imagePaste( thePhoto, watermark, 0, 0);
imageWrite( thePhoto, "images/final/upload.jpg" );

This is nothing mind-blowing - it's merely straightforward code supported natively by Coldfusion with no need for external libraries.

Here's how you do an HTTP call in Coldfusion.

cfhttp( url="https://api.chucknorris.io/jokes/random" ) {}

One line of code. Uno. That's it. The JSON is stored in cfhttp.fileContent. There's no additional libraries needed - no jQuery, no Axios, and no weird function names (_cough file_get_contents().

Not convinced? Take a look at this. In Coldfusion, sending emails is a single function.

cfmail( to="me@example.com", from="test@you.com", subject="This is an email" ) {
    writeOutput('Hello from your website!');
}

ONE LINE. (plus email body.) Need to add an attachment? That's two lines.

cfmail( to="me@example.com", from="test@you.com", subject="Daily Report" ) {
    cfmailparam( file="/assets/generated/report.pdf" );
}

Just for comparison, here's how you send an email in PHP. Look, I'm not here to bash PHP. Much. :) I get that it does a lot of things well, once you drop in your library of choice. My point is that CF has no need for third-party libraries in most cases.

Why Not Coldfusion?

Coldfusion is not โ€œjust anotherโ€ programming language - it is a simple, super-powerful one with familiar syntax, great Java integration and easy straightforward configuration. Why CF? Well... why not?

Top comments (1)

Collapse
 
sebgmc profile image
Sebastiaan van Dijk

Too bad the link to rasia.io is dead:

Lucee 5.2.7.62 Error (database)
Message The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
Stacktrace The Error Occurred in
/org/lucee/cfml/Base.cfc: line 110
called from /org/lucee/cfml/Query.cfc: line 35
called from C:\www\rasiach\preside\system\services\database\SqlRunner.cfc: line 55
called from C:\www\rasiach\preside\system\services\presideObjects\PresideObjectService.cfc: line 2933
called from C:\www\rasiach\preside\system\services\presideObjects\PresideObjectService.cfc: line 255
called from C:\www\rasiach\preside\system\services\presideObjects\PresideObjectDecorator.cfc: line 53
called from C:\www\rasiach\preside\system\services\siteTree\SiteService.cfc: line 228
called from C:\www\rasiach\preside\system\coldboxModifications\ioc\DelayedInjector.cfc: line 36
called from C:\www\rasiach\preside\system\interceptors\SES.cfc: line 245
called from C:\www\rasiach\preside\system\interceptors\SES.cfc: line 24
called from C:\www\rasiach\preside\system\externals\coldbox-standalone-3.8.2\coldbox\system\web\context\InterceptorState.cfc: line 370
called from C:\www\rasiach\preside\system\externals\coldbox-standalone-3.8.2\coldbox\system\web\context\InterceptorState.cfc: line 260
called from C:\www\rasiach\preside\system\externals\coldbox-standalone-3.8.2\coldbox\system\web\context\InterceptorState.cfc: line 121
called from C:\www\rasiach\preside\system\externals\coldbox-standalone-3.8.2\coldbox\system\web\services\InterceptorService.cfc: line 142
called from C:\www\rasiach\preside\system\coldboxModifications\services\InterceptorService.cfc: line 40
called from C:\www\rasiach\preside\system\externals\coldbox-standalone-3.8.2\coldbox\system\web\services\RequestService.cfc: line 73
called from C:\www\rasiach\preside\system\coldboxModifications\Bootstrap.cfc: line 62
called from C:\www\rasiach\preside\system\coldboxModifications\Bootstrap.cfc: line 22
called from C:\www\rasiach\preside\system\Bootstrap.cfc: line 42
called from C:\www\rasiach\Application.cfc: line 7

But we get a lot of useful information for the error page :-D