Viewing By Entry / Main
May 20, 2008
OK, now I'm ticked!

WTF is it with CFers that they think they have to mess about determining what the path separator is on every platform? In a pathetic attempt to be cross-platform, I see all sorts of convoluted code that tries to strip characters out of paths or check the O/S version in an attempt to establish whether \ or / is the right thing to use.

Word up CFers: / always works. We're using Java now and / works on Windows. Yes, really. / works on Windows, Mac and Unix. Instant cross-platform compatibility.

Making a path work on all platforms is a matter of simply doing:

path = replace(path,"\","/","all);
No messing about. Just convert Windows silly \ to / and you're done. It works everywhere.

Please stop trying to be cross-platform and do the right thing instead.

What triggered this rant? The latest varScoper code doesn't work on Mac OS because of this nonsense. Change line 29 of varScoper.cfm to just:

<cfset var pathsep = "/" />
None of that silly checking platform stuff. "/". Just. Works.

Comments

Hey Sean,

This was placed in because there was a new "directoryexcludelist" option within the new properties file. The thought was that a developer on windows would more or less write their directory path with c:\ and not c:/ so the code was to be smart enough to look for this.

It may just be best to keep a standard (use /) and note that as a comment within the properties file.


@Pat, just process the paths with:

path = replace(path,"\","/","all);

Works on every platform. Really.

"The thought" was a Windows thought. A bad one.


Yup. Already have it in and am testing it now.

Well Windows is Windows and that's all I am going to say about that :-)


@Sean,

I have to admit that I do find the slash programmatically :( Something like:

Server: Left( REReplace( GetCurrentTemplatePath(), "^[^\\/]*", "", "all" ), 1 )

Web: "/"

I only do it once, though, and then I use two functions to encapsulate it's use:

CleanServerPath() CleanWebPath()

I know you say it works in all systems, but I swear that even in MX, I have run into problems where it was causing problems not having the proper slashes.

Maybe I am totally crazy though :)


Pardon my ignorance, but as Sean mentioned we are now on Java. Even a config file, with hard coded paths shouldn't be set up.

It would be my view that everything be relative to the application. This way if the code is moved between OS's or platforms, we know where everyting will be.

If it has to be jard coded, Coldfusion is smart enough to know what OS it is running on. Why, because Java does all that work for us...

I think it was a nice thought, maybe in the days before Java one would need to do this:-)


You tell em!!!


Amen, bother.

But ... it has, to the best of my knowledge, pretty much *always* worked, even in pre-Java days. I've been using "/" in code since at least as far back as v4.


Sean,

In the case you are referring to I know you're correct. However, I'm doing a lot of work with cfdirectory created paths, which report the directory information in the OS format. What's wrong with using createObject("java", "java.io.File").separator to figure out the OS's fileseparator and using that dynamically?


LOL


I guess you're not a fan of using:

createObject("java", "java.lang.System").getProperty("file.separator")

either then?


@Rick , good to know re: pre-MX versions. My first experience of CFML was early builds of what became 6.0 so I have no knowledge of CF5 and earlier (fortunately?).

@Terrence, expandPath() and getBaseTemplatePath() etc also return paths containing the native OS separator but I just run that replace() on them and all's well.

@David, no, that seems to be the worst of all worlds to me - using Java to get a value that Java doesn't actually care about :)

Fusebox 4 used to mess about getting the native OS delimiter and then was full of nasty concatenation code to construct file paths. Fusebox 5 uses / throughout and the file handing code is much cleaner.


BTW, in case anyone thinks I'm picking on varScoper here, I had both Pat and Mike on IM last night about the issue and they had the fix in place before I'd finished my blog post.

It's really just one of my pet peeves with CFML code. I have several pet peeves with CFML code. I may blog about some of the others over the next week or two since it seems to get a response! :)


" "The thought" was a Windows thought. "

hehehe, classic.


Windows XP has problems with / when a drive already has a working directory below the root.

For example, if at c:\, cd /temp works, but once you are at c:\temp, cd /temp fails, as it doesn't recognise the leading / as a root directory.

Go figure.

I don't know if this suggests possible problems for MX?


@Norkle, sounds like an issue with XP's 'cd' command. That's not a problem for file manipulation in Java.


Sean,

Some more rants like this one would be welcome. I've always written code to handle delimiters and never heard a peep from anyone that it was unnecessary.

Excuse the sound of ripping code . . .


I knew that it accepted forward slashes in Windows (heck, you can even mix-and-match fwd slashes and back slashes), but I still usually would do code to clean it up because I didn't know how "official" that support is. Do you? Wouldn't be very happy if stuff like that broke if a future version made its expectations more strict.


Sean,

Yes more rants like this good. I think too often people want to be diplomatic about things, but if people consider you to be a reasonable authority then bringing up issues in a direct way is good.

Also makes for fun reading :-D


Post Your Comments
Name:
Email Address:
Comments
*** Please note that all comments require moderation so it may be some time before your comment posts to this blog! ***
Remember My Information:
 



Hosting provided by