[phobos] std.path proof of concept

Lars Tandle Kyllingstad lars at kyllingen.net
Mon Apr 26 01:01:14 PDT 2010


On 04/23/2010 05:26 PM, Andrei Alexandrescu wrote:
> On 04/23/2010 10:23 AM, Steve Schveighoffer wrote:
>> I would make a suggestion that the Windows version allows forward
>> slash for a dir separator as input. "C:/foo/bar.txt" and
>> "C:\\foo/bar.txt" are both valid paths on Windows.
>
> Makes sense. On an overall note, without having much time to look into
> this, I wish very strongly we strive to define OS-independent path
> abstractions before defining OS-dependent ones. Once the Windows vs.
> Posix breach is in, it'll only grow larger because it requires less
> design to put stuff in there.

I think I may be explaining myself a bit badly here, so please allow me 
to clarify:

For the most part, I want std.path to work *just as it does now*.

If you call doStuffWith(path) on POSIX, it does stuff in the POSIX way, 
and if you call it on Windows, it does stuff in the Windows way.  Code 
using it will automatically work on both platforms.

The only difference will be that if you for some reason need to 
manipulate non-native paths, you will be allowed to do so by adding a 
prefix to your functions, e.g. Path!posix.doStuffWith(path).


Rationale:

  * The code is already in Phobos, it's just string manipulation
    and doesn't require any special OS support, and there is
    thus *no need* to hide it from the user inside version(OS)
    blocks.

  * Handling non-native paths is not an obscure need.  Examples
    include:
      - FTP and similar
      - Archive manipulation (for instance, the ZIP format uses
        POSIX paths internally)

I'd argue that this doesn't introduce more of a Windows/POSIX breach 
than there already is in Phobos.  I mean, in principle there is nothing 
preventing you from adding OS-specific stuff to std.stdio except common 
sense, and it will be the same here.

-Lars


More information about the phobos mailing list