Making Your ColdFusion Applications More Platform Independent (Part I)

One of the things I really like about ColdFusion is that it is platform independent. That’s important to me since I use OS X, Linux and Windows on a regular basis, and I like to be able to run the same ColdFusion code on all three platforms. To have this level of flexibility, however, you have to plan ahead a little. ColdFusion is a platform independent language, however if you are not careful, you can very easily write code in a platform specific manner.

The two most common programming practices that I see which keep code from being platform independent is the indiscriminate use of case, and the hardcoding of path separators. This post addresses the importance of being consistent with your case. (My next post will address path separators.)

Platform independent applications must be consistent and accurate in their use of case when referencing files since most Unix operating systems (with the exception of OS X) are case sensitive. In other words, if your files are named with mixed case (like inventoryReport.cfm) you must use the proper case in referencing them on a Unix server. On Windows, you can get away with “inventoryreport.cfm” or even “INVENTORYREPORT.CFM”, however on a Unix platform, you will get a 404 if you do not reference files accurately. Additionally, make sure you use all lowercase when naming your components. ColdFusion MX will automatically lower-case your component names, which you would never notice on Windows, however on Unix, it will become apparent very quickly when you start getting errors that your components do not exist.

For Unix users, case consistency is second nature, however many Windows users mix case on a regular basis. If you want to write platform independent ColdFusion code (which means if you ever envision distributing your code in any way), start paying attention to case.

In my next post, I will write about the pitfalls of path separators, as well as post some code that will do some of the work of making your apps platform independent for you.

Comments are closed.