|
|
Created:
13 years, 7 months ago by r Modified:
13 years, 7 months ago Reviewers:
CC:
niemeyer, r2, rsc, gustavo_niemeyer.net, golang-dev Visibility:
Public. |
Descriptionpath/filepath: Dir
There was Base but not Dir, so fill in the gap.
Patch Set 1 #
Total comments: 1
Patch Set 2 : diff -r 8206c6c7ebd4 https://go.googlecode.com/hg/ #Patch Set 3 : diff -r 8206c6c7ebd4 https://go.googlecode.com/hg/ #Patch Set 4 : diff -r 8206c6c7ebd4 https://go.googlecode.com/hg/ #Patch Set 5 : diff -r 8206c6c7ebd4 https://go.googlecode.com/hg/ #Patch Set 6 : diff -r 747c04659b0f https://go.googlecode.com/hg/ #MessagesTotal messages: 23
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
Sign in to reply to this message.
LGTM. Besides being Base's complement, makes manipulation slightly simpler in some cases by enabling calls like f(filepath.Dir(path)). Should the path package receive the counterpart too?
Sign in to reply to this message.
http://codereview.appspot.com/5503067/diff/1/src/pkg/path/filepath/path_test.go File src/pkg/path/filepath/path_test.go (right): http://codereview.appspot.com/5503067/diff/1/src/pkg/path/filepath/path_test.... src/pkg/path/filepath/path_test.go:442: {"abc/def", "abc"}, Hmm.. I do wonder about this case, on a second look. Should this have a trailing slash, to match Split's behavior? It may be slightly surprising that the result of Split(path) and Dir(path) yield different dir values.
Sign in to reply to this message.
On Dec 22, 2011, at 10:27 AM, n13m3y3r@gmail.com wrote: > > http://codereview.appspot.com/5503067/diff/1/src/pkg/path/filepath/path_test.go > File src/pkg/path/filepath/path_test.go (right): > > http://codereview.appspot.com/5503067/diff/1/src/pkg/path/filepath/path_test.... > src/pkg/path/filepath/path_test.go:442: {"abc/def", "abc"}, > Hmm.. I do wonder about this case, on a second look. Should this have a > trailing slash, to match Split's behavior? It may be slightly surprising > that the result of Split(path) and Dir(path) yield different dir values. this was how the whole thing started, with someone complaining about the trailing slash. i can't make everyone happy, it seems. at least the behavior is documented. what do you want? i'll do what you want. it's just a +1 on the string to put it back, but it's much clunkier to remove. -rob
Sign in to reply to this message.
I think Dir should return the same form that Clean does, which means no trailing slash except for the root directory. That is not always what you want, but neither is the other. Russ
Sign in to reply to this message.
On Dec 22, 2011, at 11:20 AM, Russ Cox wrote: > I think Dir should return the same form that Clean does, > which means no trailing slash except for the root directory. > That is not always what you want, but neither is the other. That's the documented behavior of the implementation here. -rob
Sign in to reply to this message.
Code looks good. The comment is not quite right: Dir(`/foo`) = `/` but it doesn't fall under the specified case. Also, on windows presumably Dir(`c:\foo`) = `c:\`. Maybe The returned path does not end in a separator unless it is the root directory. Russ
Sign in to reply to this message.
Please add a test for /foo too.
Sign in to reply to this message.
> this was how the whole thing started, with someone complaining about the trailing slash. i can't make everyone happy, it seems. at least the behavior is documented. > > what do you want? i'll do what you want. it's just a +1 on the string to put it back, but it's much clunkier to remove. My vote is to either: 1) Remove the slash from both Split and Dir (behavior seems preferable, but incompatible if people are blindly assuming the slash) 2) Keep the slash on both People will probably use Split and Dir interchangeably, and having them with differing outcomes seems error prone. -- Gustavo Niemeyer http://niemeyer.net http://niemeyer.net/plus http://niemeyer.net/twitter http://niemeyer.net/blog -- I'm not absolutely sure of anything.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, n13m3y3r@gmail.com, r@google.com, rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
I would prefer not to touch Split. It has the very nice property that dir, file := path.Split(name) dir+file == name! I don't know whether we should keep Base (and now Dir) different from Split or make them wrappers around Split that select one or the other result. Russ
Sign in to reply to this message.
On Dec 22, 2011, at 11:25 AM, Gustavo Niemeyer wrote: >> this was how the whole thing started, with someone complaining about the trailing slash. i can't make everyone happy, it seems. at least the behavior is documented. >> >> what do you want? i'll do what you want. it's just a +1 on the string to put it back, but it's much clunkier to remove. > > My vote is to either: > > 1) Remove the slash from both Split and Dir (behavior seems > preferable, but incompatible if people are blindly assuming the slash) > 2) Keep the slash on both > > People will probably use Split and Dir interchangeably, and having > them with differing outcomes seems error prone. If Split is going to change, that should happen in a separate CL. I might try that as an experiment and see if the world salutes. -rob
Sign in to reply to this message.
On Dec 22, 2011, at 11:38 AM, Russ Cox wrote: > I would prefer not to touch Split. > It has the very nice property that > dir, file := path.Split(name) > dir+file == name! > > I don't know whether we should keep > Base (and now Dir) different from Split > or make them wrappers around Split > that select one or the other result. I am happy to leave split as it is and say why. I am also happy to have Dir drop the trailing slash, since that's almost always what you want, and it's much easier code-wise to add it back than to take it off. -rob
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, n13m3y3r@gmail.com, r@google.com, rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
LGTM barring any good arguments that might arise
Sign in to reply to this message.
> I would prefer not to touch Split. > It has the very nice property that > dir, file := path.Split(name) > dir+file == name! It's an interesting property, but it doesn't seem very useful in practice, and probably not worth the distinction from Dir. Note some curious differences, if I understand Dir (haven't run it): - Case 1: dir1, _ := filepath.Split("/a/b/") dir2, _ := filepath.Split(dir1) println(dir2) // "/a/b/" dir1 := filepath.Dir("/a/b/") dir2 := filepath.Dir(dir1) println(dir1) // "/a - Case 2 (this looks like a bug in Split): dir1, _ := filepath.Split(".") println(dir1) // "" dir1 := filepath.Dir(".") println(dir1) // "." - Case 3 (this looks like a bug in Dir): dir1, _ := filepath.Split("a") println(dir1) // "" dir1 := filepath.Dir("a") println(dir1) // "a" I really wouldn't like to have to remember what I'm really doing every time I touch either of them. -- Gustavo Niemeyer http://niemeyer.net http://niemeyer.net/plus http://niemeyer.net/twitter http://niemeyer.net/blog -- I'm not absolutely sure of anything.
Sign in to reply to this message.
On Thu, Dec 22, 2011 at 15:05, Gustavo Niemeyer <gustavo@niemeyer.net> wrote: > It's an interesting property, but it doesn't seem very useful in > practice, and probably not worth the distinction from Dir. Not changing split. It's the most useful of the bunch.
Sign in to reply to this message.
Hello n13m3y3r@gmail.com, r@google.com, rsc@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
New attempt, different approach, better results, same idea. -rob
Sign in to reply to this message.
LGTM Please copy same into path. I am certain this is wrong for Windows but not sure how to test `c:\foo` -> `c:\` only on Windows.
Sign in to reply to this message.
On Dec 22, 2011, at 1:37 PM, rsc@golang.org wrote: > LGTM > > Please copy same into path. > I am certain this is wrong for Windows > but not sure how to test `c:\foo` -> `c:\` only > on Windows. if this is where we're going, i'll do path in a separate CL. is this where we're going? -rob
Sign in to reply to this message.
On Thu, Dec 22, 2011 at 16:43, Rob 'Commander' Pike <r@google.com> wrote: > if this is where we're going, i'll do path in a separate CL. is this where we're going? i think it's fine. i think that you can recognize a root if the last separator is also the first separator and IsAbs returns true. that definition handles / and c:\. russ
Sign in to reply to this message.
*** Submitted as http://code.google.com/p/go/source/detail?r=f13664d9df19 *** path/filepath: Dir There was Base but not Dir, so fill in the gap. R=n13m3y3r, r, rsc, gustavo CC=golang-dev http://codereview.appspot.com/5503067
Sign in to reply to this message.
|