digitalmars.D.learn - std.path.buildPath
- Russel Winder via Digitalmars-d-learn (20/20) Jun 03 2017 =46rom the manual page on std.path.buildPath:
- Jacob Carlborg (6/16) Jun 03 2017 Unfortunately it's been like this since forever. I mean, I checked the
- David Nadlinger (9/14) Jun 03 2017 Of all people, I certainly didn't expect you to stray so far from
- Jesse Phillips (3/14) Jun 03 2017 What is your expected behavior? Throw an exception? You can't
- Jacob Carlborg (5/7) Jun 04 2017 Of course you can. I expect buildPath("/foo", "/bar") to result in
- Patrick Schluter (4/10) Jun 04 2017 buildPath("/usr/bin", "/usr/bin/gcc")
- Jacob Carlborg (16/18) Jun 04 2017 Says who? It might be exactly what I want. The case that came up is
- Russel Winder via Digitalmars-d-learn (20/48) Jun 12 2017 Says Guido et al. it seems, Python has in os.path and pathlib exactly
- Russel Winder via Digitalmars-d-learn (13/21) Jun 04 2017 And Python, Groovy, Java, Kotlin, Ceylon, C++, =E2=80=A6
- Ryan Frame (6/17) Jun 11 2017 Python 3.5.1 on my machine:
- Russel Winder via Digitalmars-d-learn (26/46) Jun 12 2017 ####### #### you are absolutely right, and it is clearly stated in the
=46rom the manual page on std.path.buildPath: writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz" writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz" writeln(buildPath("/foo", "/bar")); // "/bar" I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff. "If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped." I cannot find any excuse for this to be even remotely reasonable. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jun 03 2017
On 2017-06-03 16:12, Russel Winder via Digitalmars-d-learn wrote:From the manual page on std.path.buildPath: writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz" writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz" writeln(buildPath("/foo", "/bar")); // "/bar" I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff. "If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped." I cannot find any excuse for this to be even remotely reasonable.Unfortunately it's been like this since forever. I mean, I checked the git history, it's been like this for as long as we have history, including when it was called "join". -- /Jacob Carlborg
Jun 03 2017
On Saturday, 3 June 2017 at 14:12:03 UTC, Russel Winder wrote:I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff.Of all people, I certainly didn't expect you to stray so far from the tone appropriate here. Please keep it civil.I cannot find any excuse for this to be even remotely reasonable.I suspect the original author had applications in mind where you want to resolve user-specified file system paths that might be relative or absolute. One could just use buildPath to prepend the root path if necessary. (Whether this is useful or just unnecessarily error-prone is another question, of course.) — David
Jun 03 2017
On Saturday, 3 June 2017 at 14:12:03 UTC, Russel Winder wrote:From the manual page on std.path.buildPath: writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz" writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz" writeln(buildPath("/foo", "/bar")); // "/bar" I have no idea what drugs the person who chose that last one to be correct semantics was on at the time, but it was some seriously bad stuff. "If any of the path segments are absolute (as defined by isAbsolute), the preceding segments will be dropped." I cannot find any excuse for this to be even remotely reasonable.What is your expected behavior? Throw an exception? You can't really append an absolute path to another.
Jun 03 2017
On 2017-06-04 07:44, Jesse Phillips wrote:What is your expected behavior? Throw an exception? You can't really append an absolute path to another.Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves. -- /Jacob Carlborg
Jun 04 2017
On Sunday, 4 June 2017 at 15:56:58 UTC, Jacob Carlborg wrote:On 2017-06-04 07:44, Jesse Phillips wrote:buildPath("/usr/bin", "/usr/bin/gcc") /usr/bin/usr/bin/gcc is obviously wrong. I think the semantic is not as illogical as it seem at first glance.What is your expected behavior? Throw an exception? You can't really append an absolute path to another.Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves.
Jun 04 2017
On 2017-06-04 19:05, Patrick Schluter wrote:buildPath("/usr/bin", "/usr/bin/gcc") /usr/bin/usr/bin/gcc is obviously wrong.Says who? It might be exactly what I want. The case that came up is inside DStep. The user provides a set of files C header to be translated to D modules. The user also provides a flag to indicate where to place the resulting files. I wanted to be able to keep the existing directory structure of the header files in the new target location. Example: dstep -o result /usr/include/libxml2/libxml/*.h The internals of DStep will do something like: buildPath("result", "/usr/include/libxml2/libxml"); Which currently results in "/usr/include/libxml2/libxml". The end result is that DStep will try to write a file to "/usr/include/libxml2/libxml", which the user most likely will not have access to (without using sudo). I expected the result of buildPath to be "result/usr/include/libxml2/libxml". -- /Jacob Carlborg
Jun 04 2017
On Sun, 2017-06-04 at 21:32 +0200, Jacob Carlborg via Digitalmars-d- learn wrote:On 2017-06-04 19:05, Patrick Schluter wrote: =20Says Guido et al. it seems, Python has in os.path and pathlib exactly this behaviour.buildPath("/usr/bin", "/usr/bin/gcc") =20 /usr/bin/usr/bin/gcc is obviously wrong.=20 Says who? It might be exactly what I want. The case that came up is=20 inside DStep. The user provides a set of files C header to be translated=20 to D modules. The user also provides a flag to indicate where to place=20 the resulting files. I wanted to be able to keep the existing directory=20 structure of the header files in the new target location. Example:dstep -o result /usr/include/libxml2/libxml/*.h =20 The internals of DStep will do something like: =20 buildPath("result", "/usr/include/libxml2/libxml"); =20 Which currently results in "/usr/include/libxml2/libxml". The end result=20 is that DStep will try to write a file to "/usr/include/libxml2/libxml",=20 which the user most likely will not have access to (without using sudo).=20 I expected the result of buildPath to be=20 "result/usr/include/libxml2/libxml".Sadly Python tells us otherwise just as D does. It is perhaps worth noting in passing that D path support seems very like os.path and Python folk are giving that up in favour of pathlib. Java/Kotlin/Groovy have also gone the same way. The implication is that D needs better path support than it currently has to keep up with the evolutions in other languages. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Jun 12 2017
On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote:On 2017-06-04 07:44, Jesse Phillips wrote: =20And Python, Groovy, Java, Kotlin, Ceylon, C++, =E2=80=A6 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winderWhat is your expected behavior? Throw an exception? You can't really append an absolute path to another.=20 Of course you can. I expect buildPath("/foo", "/bar") to result in=C2=A0 "/foo/bar". That's how Ruby behaves.
Jun 04 2017
On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote:On Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via Digitalmars-d- learn wrote:Python 3.5.1 on my machine: >>> os.path.join("/asdf", "/bcd") '/bcd' >>> os.path.join("asdf", "/bcd") '/bcd'On 2017-06-04 07:44, Jesse Phillips wrote:And Python, Groovy, Java, Kotlin, Ceylon, C++, …What is your expected behavior? Throw an exception? You can't really append an absolute path to another.Of course you can. I expect buildPath("/foo", "/bar") to result in "/foo/bar". That's how Ruby behaves.
Jun 11 2017
On Sun, 2017-06-11 at 13:21 +0000, Ryan Frame via Digitalmars-d-learn wrote:On Sunday, 4 June 2017 at 18:15:36 UTC, Russel Winder wrote:documentation that this is the expected behaviour. Clearly, I have never tried doing that in 20 years of playing with Python. And it has never come up in 12 years of running Python workshops! This behaviour is reinforced by pathlib which is the modern way of doing paths in Python, replacing os.path: import pathlib p =3D pathlib.Path() p =3D p.joinpath('/', 'usr', '/local', '/bin') print(p) result /bin. So given Python is one of the targets for D, consistency of behaviour implies D is currently doing the right thing. =20 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winderOn Sun, 2017-06-04 at 17:56 +0200, Jacob Carlborg via=20 Digitalmars-d- learn wrote:=20 Python 3.5.1 on my machine: =20 >>> os.path.join("/asdf", "/bcd") '/bcd' >>> os.path.join("asdf", "/bcd") '/bcd'On 2017-06-04 07:44, Jesse Phillips wrote: =20=20 And Python, Groovy, Java, Kotlin, Ceylon, C++, =E2=80=A6What is your expected behavior? Throw an exception? You can't really append an absolute path to another.=20 Of course you can. I expect buildPath("/foo", "/bar") to=20 result in "/foo/bar". That's how Ruby behaves.
Jun 12 2017