Wow, that title is a heck of a lot more serious than I intended it to be. A few days ago I was working with some code Dan Swizter had written for BlogCFC. I ran into an issue when code he had written failed to run on my Mac. It turned out to be a simple enough mistake, but it occurred to me that it may make sense to create a simple list of development guidelines for ColdFusion programmers to ensure maximum portability of their web applications across Windows, Linux, and Mac platforms. I'm just starting this guide off with a few tips, and I hope my readers can help flesh it out. Once enough content is gathered, I'll create a proper document for it and link it up from the Guides pod to the right. So without further ado, here are some things to keep in mind when writing your code.
-
When it comes to creating file paths, don't worry about \ versus /. Just use /. The / character will work on Windows, OSX, and Linux systems. Yes, you can write code to check for the proper file path separator, but if you are just reading or writing to a file, why worry about it?
-
Don't let case sensitivity ruin your day. On more than one occasion I've worked with code that was fine on OSX and Windows, but failed on Linux because of case sensitivity issues. The simplest solution is to simple lowercase everything. Ie: klingon.cfc, ships.cfm, index.cfm, etc. Of course, the exception to this are the files ColdFusion use for application-specific functionality: Application.cfc, Application.cfm, and onRequestEnd.cfm. Everything else though should be lowercased.
-
Minimize the use of operating system specific features called via cfexecute. This may be out of your control, but if you write CFML that makes use of cfexecute to run command line code, you want to ensure you are using a command line tool that runs on multiple operating systems, and runs with a similar API. You may not be able to though, so at minimum, this is a perfect example of something that should be carefully documented for your client so they are aware of the dependency.
Ok, what am I forgetting folks? Try to focus on things that should apply to most cases. Odd edge cases may not make sense in a general document like I the one I want to create. (But those tips could always be added to an Errata section).

Archived Comments
Don't forget that case-sensitivity applies to SQL, too: Table names (but not column names) are case-sensitive in MySQL on Linux, by default. Ran into this when a host's Windows CF plans used MySQL databases hosted on Linux servers.
Similar to / vs \, never hardcode paths: always use expandpath() and/or relative paths; that way you don't have to worry about C:\. That's just a general portability tip, though.
Keep a tight control on all external technologies needed, not just cfexecute calls. URL rewriting, for instance; for IIS, I use ISAPI_Rewrite v3 because it's compatible w/ apache-style .htaccess files. Assuming you're not going to be running Apache on Windows, anyway.
It's also another reason to avoid Access databases; Access DSNs are only available on Windows hosts.
Those aren't strictly CF-specific, but combined with what you've already got, they're everything I've run into thus far with my Windows-office, Linux-home, mixed-host experience.
Seems you've never seen the "Hi I'm Linux" adverts before!
http://www.youtube.com/watc...
Linux is a woman, not someone from Tron. :)
Since it runs on the JVM and it's supposed to be platform agnostic, I guess there's just file write operations like you mentioned.
- Get in the habit of using getDirectoryFromPath() and it's ilk for file operations?
I believe cfexecute on linux invokes fork() and that can be very bad - I don't know how windows handles it.
You could almost extend this into an Apache vs IIS discussion and there would be some more things that pop up.
I don't know what the limit on windows based machines but there is a ulimit max on UX machines that is like 2000 open files so if you are doing a bunch of file reads in high traffic it can hurt.
- If you have the chance, use a case sensitive file system for development. OS-X file systems can be case sensitive, too. ;-)
- Use VMs to test on various operating systems!
Chris
I ran into that with the QueryParam Scanner project on RIAforge. The last update was not reading directories on any Unix-based filesystem (I tested on both OS X and Unix). It turns out the problem was how he had written the code to recurse the directories, he had written it solely for a Windows system. I sent him a patch that I wrote to get it to work on all environments, but I'm not sure if he ever released it or not.
My work servers are all Unix, and my personal development is OS X. My Personal production is windows, so I set server specific application-level variables mapping out the directories and using the "proper" slash syntax for each. I did not know that forward slashes would work in Windows, thanks for that tip!
Will the Bolt IDE be restricted to Mac and Windows like the new versions of Flex Builder?
I certainly hope not
@Michael: Only Adobe is allowed to talk about Bolt. You know that. ;)
@Elliott: No one is better than Tron guy though.
@All: Thanks for the additions, keep em coming.
Ray, I've got a post that covers a lot of this:
http://www.iknowkungfoo.com...
Plus as of 8.0.1, CF has become even more case-sensitive:
http://www.adobe.com/go/kb4...
http://www.mkville.com/blog...
HTH
@Ray
I think that Flynn would have been a better representation of Linux because he's a true coder!
I use <cfset application.fs = createObject("java", "java.lang.System").getProperty("file.separator")> to fight \ vs /
@Patrick: Of course, the point I had made was that many times, you don't NEED to know the 'real' separator. Just use /.
If I can chime in here...
This was fresh in my mind yesterday when I was coding a multi-file uploader for a client and I used Ray's forward slash setup in a Windows environment and it worked like a charm. I've seen many postings arguing about this in the past and I'm really starting to believe that many CF developers are making more out of this than necessary. What are you gaining by throwing down the java? Everyone acts as if there is to be no time or thought spent when deploying an application in terms of what environment it will live in. If you have to store a bit of path data in a database table or your Application.cfc file and take a minute or two when deploying the app to set it up then so be it. I'd rather spend my time on feature development then geeking out over the file system.
Guys, I finally made time to 'formalize' this into a page on my blog:
http://www.coldfusionjedi.c...
Thoughts? I appreciate all the comments here, but I only specifically called out folks where I used their content in the guide. If that is bad, let me know!
Also, I realize the guide may not be perfect, but is it ok for a first real release? Will it be useful?