Path as an object in std.path
Robert Clipsham
robert at octarineparrot.com
Thu Jun 6 16:50:11 PDT 2013
On Thursday, 6 June 2013 at 15:36:17 UTC, Walter Bright wrote:
> On 6/4/2013 11:27 PM, Dylan Knutson wrote:
>> I'd like to open up the idea of Path being an object in
>> std.path. I've submitted
>> a pull
>> (https://github.com/D-Programming-Language/phobos/pull/1333)
>> that adds a
>> Path struct to std.path, "which exposes a much more palatable
>> interface to path
>> string manipulation".
>
>
> I've succumbed to the temptation to do this several times over
> the years.
>
> I always wind up backing it out and going back to strings.
As another data point: Java 7 introduces new Path and Paths
objects:
http://docs.oracle.com/javase/7/docs/api/java/nio/file/Paths.html
So they clearly think using an object(s) for it is useful.
-----
Without even thinking about the API, just using it, all the code
I've written in the past couple of weeks looks something like
this:
Path p = Paths.get(someDir, someOtherDir);
p = p.subpath(otherPath, p.getNameCount());
Path file = p.resolve(someFile);
print(file.toString());
file.toFile().doSomething();
ie. All my code is converting to/from a Path object purely for
dealing with Windows and Posix / vs \ differences and doing
sub-paths. Seems a bit pointless when we could just use free
functions in my opinion.
More information about the Digitalmars-d
mailing list