« My New Mobile Office | Main | JavaScript Support for Eclipse »
July 30, 2005
Making Your ColdFusion and Java Applications More Platform Independent (Part III)
Making Your ColdFusion and Java Applications More Platform Independent (Part III)
Two years ago (has it really been that long?!), I made a couple of posts about how to make your ColdFusion and Java applications more platform independent. The first post covered the importance of case consistency, and the second talked about not hard-coding path separators since they are different on different platforms. Well, all this time later, I actually have a third piece of advice: don't hard-code new line characters.
I'm switching my development environment over from OS X to Windows (I haven't used Windows consistently in many years, so I figured it was time to give it a try again), and while trying to get MXNA running locally, I came across a bug that I'd never seen in development (on OS X) or on production (Linux). The problem was this line of code:
<cfset blArray = listToArray(blacklist, chr(10))/>
The code is trying to convert a line-separated list into an array. On OS X and Linux, it works fine since the new line character is "line feed", or chr(10), or \n, but on Windows, the code didn't work because a new line is "line feed" and "carriage return", or chr(10) & chr(13), or \n and \r. So rather than ever having to worry about this again, I used a little Java trick to make the code run in any environment. Now it looks like this:
<cfset blArray = listToArray(blacklist, createObject("java", "java.lang.System").getProperty("line.separator"))/>
Even with a language like Java (and hence, ColdFusion), if you want your code to be truly platform independent, it takes a little work. The good news is that once that was fixed, MXNA was up and running in my development environment perfectly.
Posted by cantrell at July 30, 2005 10:50 AM | References
Related Entries
- CFEclipse and Flex Builder 2: Happy Together
- From Vim to Eclipse
- Why Distinguish Between GETs and POSTs?
- Don't Forget to Scope CFHTTP
- MXNA Java Category
Comments
"I'm switching my development environment over from OS X to Windows (I haven't used Windows consistently in many years, so I figured it was time to give it a try again" -- Christian! Surely you're not deserting us... ;)
Posted by: Stephanie at July 30, 2005 09:30 PM
Not deserting. Just exploring. I still have a Mac close by at all times.
Posted by: Christian Cantrell at July 31, 2005 11:34 PM
Ok, maybe a silly question, but if a CRLF in OSX and Linux is Chr(10), and a CRLF in Windows is Chr(13) & Chr(10), why would ListToArray(foo, Chr(10)) fail because all the OS's listed above contain Chr(10).
Posted by: JediHomer at August 1, 2005 03:25 AM
If you use two characters for CF list functions, they can use one of them to determine the list items. This means you can safely use , this should work on any platform.
Posted by: Murat at August 2, 2005 10:51 PM
I have kinda of the problem you describe, but the difference is that the server is linux, and the browser is on Windows, so, the System.getProperty("line.separator") trick won't make it there.
any idea ?
Posted by: Brice Laurencin at August 25, 2005 02:47 AM
Brice, this will still work fine for your ColdFusion code which is running on the server.
Christian
Posted by: Christian Cantrell at August 25, 2005 08:26 AM
How about CFIMPORT library tags? They cannot be dynamic in path values, so wouldn't you have to hard code the path stuff? I would love to make that dynamic as i could code in the WebRoot (../../) and my the folder ultra portable without code touch ups.
Posted by: Ben Nadel at September 7, 2005 11:12 AM
Can't you use #expandpath('your relative path')# to have the path dynamicly?? I'm not really familiar with the CFIMPORT tag.. but it works for CFFILE and CFDIRECTORY tags.
Posted by: Tjarko at September 12, 2005 08:16 AM