views:

1016

answers:

2

I am using PHP, but I guess this question might be language agnostic.

With PHP, a constant is defined by PHP, called DIRECTORY_SEPARATOR. I have seen this in Joomla

define('DS', DIRECTORY_SEPARATOR); // quicker to type plus DS is easier to read in a path

I thought this looked like a good idea so I incorporated it into some of my sites. Now I'm asking myself why. I have only experience on Windows and OS X (One day Linux...) and from what I know Microsoft, Linux and Apple all use the forward slash as the directory separator.

I know it might help if one day someone changes the directory separator, but that's unlikely in the foreseeable future (at least I think so).

Is using this constant unnecessary?

+5  A: 

Mac OS Classic uses ":", for instance. See Wikipedia for details. Also it's considered good style avoiding 'magic numbers' or similar constructs.

Jan Jungnickel
+2  A: 

Windows actually uses a backslash as the directory separator, although some environments that have Windows versions will translate between forward slashes and backslashes automatically (Python comes to mind).

David Zaslavsky
Actually, I'm pretty sure Windows will accept both and translate as necessary (I can CD to /Windows from the a cmd instance just fine).
overslacked
@overslacked, partially you're right. cd D:/foo used to break, while cd /foo worked.
Jan Jungnickel