Pros and Cons of CFML vs PHP and other languages

Wed, Apr 17, 2013 at 9:55PM

It seems like the world is getting more diverse and specialized as we have a variety of choices where there used to be so few for web development.

Often, I write about how Railo and CFML benefits me.  This time I'm going to point out some differences between CFML, PHP and others languages, and highlight that CFML is not the best option for everything.

Many choices vs a single choice

They say that good design is about removing unnecessary detail.

If you measure CFML based on its design as a language, it does accomplish a fairly good mix of simple design and flexibility that few other languages can match.  While it has grown to be a bit more varied then the original implementation, it usually doesn't rush towards adding complex syntax and technical features habitually.   It typically tries to implement features that do a lot of the complex algorithms and I/O for you.

So let's say you really do need an alternative option for CFHTTP, well there isn't one available in CFML itself.  Sometimes the CFML language is too simple for solving a certain problem.  Having the language designers limit your choices will eventually cause you to run into a brick wall when it comes to optimizing performance or adding a specific feature to your application.   You could argue that you can integrate with Java to add the missing behavior, but that is not possible without significant additional learning.  Using someone else's Java code can be challenging, and if it isn't open source or a well maintained Java project, you don't know if it will remain compatible with future versions of the CFML server.   I often use a different language such as PHP, when I can't implement a feature a specific way.   Often a single small feature in PHP can be faster to write or help compensate for some other concerns which the CFML method doesn't allow.    CFML handles maintenance of larger application much easier in contrast though, so I haven't wanted to do everything in another language yet.

Community support can be limited

If no one has encountered your issue before, you are likely going to be somewhat forced to do some kind of workaround or not use that feature anymore.  You can't wait around for the software to get better.   This is where CFML can sometimes be bad.  Newer features that haven't reached a high level of maturity may not be able to work properly in fringe cases.  However, the core language is robust enough where this usually doesn't come up.

CFML is relatively less free compared to other languages

CFML software and labor is typically more expensive.  You might need more powerful hardware to host ColdFusion or Railo.  It's not a very good idea to install it on cheap shared hosting accounts.   It's more of a premium option that is better for people who run a more serious web development business.

CFML is somewhat lacking in free quality IDEs and debuggers compared to the other languages. Railo is the only good free CFML tool in my opinion, but it doesn't include a debugger.   FusionDebug is a nice software, but it carries an annual subscription price.   Also, whether you use Coldfusion Builder, Dreamweaver, IntelliJ or something else, CFML IDEs are not free.   Sure you can get free code highlighting in notepad++, but it's a bit inefficient compared to the other options as your projects grow larger.  

While CFML is not as free as Java, that cost can be fairly easily justified since you will be more productive using it.

System memory issues with CFML

CFML engines do require a substantial amount of system memory to operate correctly compared to using a more efficient statically typed language like C++ that doesn't need to run a virtual machine or a more lightweight fastCGI type language like PHP or Perl.  While Railo may start up with just 256mb to 500mb JVM heap size, that is very limited amount of memory.  I give it around 2gb for the heap and permgen memory.  This is much more then it needs, but this ensures I don't run out during peak load conditions.   I do a substantial amount of caching in memory, so it's more then just the application - its a lot of data as well.  Many languages don't really offer this easy way of caching like CFML does, so it's hard to know how much memory my app needs without the caching.  Removing the caching would make it too slow.  Most CFML apps are designed to consume some extra memory for cached data, so my situation is not unique.

It may be hard to determine how much memory your CFML application needs due to garbage collection and traffic that varies.  Because CFML does use a large amount of memory, it wouldn't be the best choice for applications that will be on small embedded systems or when you need real-time low-latency response times such as in games.  However, it may function well enough as a socket server for multiplayer synchronization.

Lightweight processes are not always faster.  The significant caching benefits offered by CFML will help you surpass PHP performance fairly easily.   PHP wastes disk I/O a great deal instead of wasting memory. Scaling to have more disk I/O usually costs more then scaling to have more memory. I'd rather have 1 copy of data in a big chunk of reserved memory, then re-building things constantly off the disk with random memory usage. If PHP was truly faster then CFML because of Java memory / garbage collection issue, then Caucho Quercus wouldn't have been able to make PHP faster on Java like it does.

CFML's simplicity can be inefficient

When you talk about language features, you have quite a lot more options to do things in nearly every other language. The OOP features and data type implementations in non-CFML languages usually have more syntax to enforce things built into the language.

You can't control whether data is passed by reference or as a copy - it has default behavior for various data types.  You can of course make manual duplicates, but it is slightly more verbose.  CFML has no support for static variables, there are limited compiler options to tweak the language.   Variables in CFC methods are global by default, which is terrible.  Railo has an option to change this, but prior to Railo 4.1, it was only possible to change this globally.  Railo 4.1 introduce local scope mode on the cffunction tag.   Other languages have namespaces to help you keep code more isolated.  You can handle these things in CFML, but it may take more code and you can't control what other developers do as well.   Because Java allocates all memory in the heap, it's slightly more costly to access memory.  However, they have done a lot to minimize this.  Other languages that have a "stack" and closer access to the CPU caches, can outperform Java/CFML in some situations.

CFML historically only had very simple I/O which saves time, but can lead to massive memory waste if you aren't careful, such as when reading a large log file with cffile. Running out of memory or causing an infinite loop in CFML/Java is often fatal and it can kill the entire application sometimes if garbage collection can't catch up with memory allocations.   There is more detailed file I/O now in CFML, so newer apps may have more complex I/O too to avoid excess memory usage.

Running out of memory with a fastcgi PHP process doesn't crash the rest of the fastcgi processes usually since each thread has a memory limit.   This makes PHP a bit more stable when memory use become an issue.  CFML needs a way to monitor and limit memory usage per thread to get around this, but there isn't anything built-in for that yet and it seems like it may hard to do this with Java. 

CFML uses a hashmap with added features for virtually all its data, which makes it quite a bit slower then using plain old Java objects.   Other dynamic languages may do the same, but it's something to consider when comparing languages for best performance.  A dynamic language spends a lot of its time searching for things in memory, rather then doing something more productive.

It seems like CFML processes have to be managed more carefully then PHP. However, PHP's lack of server is its worst feature when it comes to caching data. You can be much more productive with CFML when writing new code. Other languages may have more applications that you can reuse, but modifying and maintenance for third party solutions is often more painful then having your own solution. A lot of popular PHP apps are not written very well and have serious security concerns. If you can agree fewer lines of less precise code is better then total control enforced by verbose code, CFML is a good choice.

While all of this sounds bad, it doesn't matter much in a real application because these technical issues are handled for you in the best way that works for most situations.  If you needlessly concern yourself with the minutia of complex I/O and memory issues on every feature in your app, you'd lose a great deal of productivity and end up maintaining a lot more code.   It is more difficult to optimize complex code.  It is possible to do it wrong.

Combining and considering use of many languages instead of one

You could also consider having a mixture of CFML and Java so that you only use more detailed code when you need it. It is easier to use Java objects with CFML then it is with many other languages.

CFML is older then a lot of newcomers that propose interesting alternatives, such as node.js, clojure and ruby on rails. Those alternatives may be reaching a similar level of use and support now, but they aren't ahead by much if at all in terms of simple popularity metrics.   It's interesting that node.js appears to be the only one with continuous and substantial growth on Google Trends having surpassed ColdFusion in just 3 years.   I think people really like the idea of writing backend and frontend with the same language: Javascript.  Check out Google Trends simple language comparison.

My familiarity with other popular new languages is near zero. It appears that python is substantially more popular with many different run-time options available.  I wouldn't know how to compare python with CFML, but they say Jython version is similar to Java performance, I'm guessing they could be quite close.  

Other languages seem to be doing more to enforce programming best practices as a default convention or a compiler limitation.  Some offer a different programming style, which can be quite radically different from everything you might have learned in other languages.  Clojure implements more efficient functional programming then you can do with closures in CFM. This helps Clojure scale to many CPUs with simpler code.

Some languages are better known for the frameworks or applications built on them. ASP.NET is a framework that works with many languages. Ruby on Rails, a framework for Ruby.  Java offers several big frameworks/libraries and isn't very useful without them. Java is the glue for a large number of web technologies.  It seems like writing code in Java would be a good choice if you want to get away from dynamic languages.  

Picking a framework for CFML seems somehow less important, since it handles most of the framework related stuff for you by consuming a bunch of Java projects which are framework/library oriented in nature.  CFML makes a lot of complex Java decisions for us, so we don't need to know that much about how it works.  We don't need to worry about abstracting the database connections or all the data type details.  It's already simple enough.   What CFML does need is more applications that show off its best features.

Other languages have more vibrant communities extending the language. CFML is not being improved by as many people, though it could be in the future. A few people making careful decisions may be good for keeping it simple, but it does let other languages get ahead with more options to solve problems.

There are a lot of issues to deal with when adopting CFML.  It's not the first choice for a lot of developers, but you'll learn to appreciate how productive you can be with it if you give it a chance.

It seems there are so many languages running on Java now, that it's probably hard to explain how CFML is better then them.   You could say CFML is easier to learn, less verbose, you'll have fewer bugs.   Running as a server process is both good and bad.   Easy to do advanced caching.  Harder to keep it running stable.

Do other applications/languages built on the JVM have the same traits as CFML? 

I know the Eclipse IDE is built on Java, and it's pretty slow to start-up.  It is unstable until it gets the right amount of memory.  It is annoying to wait for a big process to start-up.   CFML / Java apps are like freight trains.  They are hard to get moving, but super powerful once in motion.
PHP and other cgi type apps are like a paper plane, you launch it and it floats around and falls to the ground.  You have to pick it up and keep throwing it.
It seems you either implement a language on a heavy-weight virtual machine or you make it lightweight for some kind of CGI type execution.   Maybe if CFML was implemented as a FastCGI app, then people would have both ways of executing it.
CFML has easy shared memory, Java integration, clustering support, security context, simple language syntax, clever html-like tags, and easy pdf generation as its killer features.

Bookmark & Share