People's answer show what I fear, which is that coexistence of similarly named Join and JoinList causes great confusion.
We could also add a PathList type with a String method.
Rémy
--
It's a reasonable goal, but
I'm not sure it's useful enough to be in the standard library and
hence be supported for N years.
--
--
What would it do when an element contains the separator?
Unix-ish systems generally allow directory names to contain ':' but you cannot include such directories in PATH. I'm not sure how it is handled for other uses; that is, do all applications using PATH-like environment variables / parameters handle it the same way as shells handle PATH, or do some of them support / require escaping colons...
If it is to be added, I'd suggest making it something like "JoinList(elem ...string) (string, error)", and return an error when an element contains the separator. That would at least allow it to correctly handle the most common case of PATH.
On Thu, Jan 10, 2013 at 5:18 AM, speter <spete...@gmail.com> wrote:
What would it do when an element contains the separator?
Unix-ish systems generally allow directory names to contain ':' but you cannot include such directories in PATH. I'm not sure how it is handled for other uses; that is, do all applications using PATH-like environment variables / parameters handle it the same way as shells handle PATH, or do some of them support / require escaping colons...
If it is to be added, I'd suggest making it something like "JoinList(elem ...string) (string, error)", and return an error when an element contains the separator. That would at least allow it to correctly handle the most common case of PATH.
but then we can't use it this way:path := filepath.JoinList(os.Getenv("PATH"), "path/to/my/test/binary")
and forced to write:path, err := filepath.JoinList(append(filepath.SplitList(os.Getenv("PATH")), "path/to/my/test/binary"))if err != nil {// what to do here?}
I don't think it is equivalent with Join(). In the case of Join(), elements can only contain '/' when they have been joined in some way previously. This is not the case when handling (lists of) directory names.
Another issue is empty directories. While it is not common for users to have the empty directory in their paths, those who do likely have it for a reason and it is generally not desirable to remove them.
On Unix systems an empty element on a path effectively means the
current directory. Try putting a ':' at the start or end of PATH, or
putting "::" in PATH.
On 10 January 2013 09:39, speter <spete...@gmail.com> wrote:
I don't think it is equivalent with Join(). In the case of Join(), elements can only contain '/' when they have been joined in some way previously. This is not the case when handling (lists of) directory names.
I think you're overthinking it, and I am sympathetic to minux's criticism. As API designers we should optimize for the common case, not the corner case. Adding AppendToList is going too far IMO. One of the main reasons for adding JoinList is for symmetry with Join, and the way Dave currently specifies it in his CL is very symmetrical. Doing some escaping (what escaping? what scheme?) on the path separator is not this function's responsibility.
--
Would JoinList need to be that smart? I'd imagine a method that took two, or more strings and inserted ':' or os specific path list separators between the elements, and returned the generated string. Nothing more.
In this situation you could do:list := JoinList(OS.GetEnv("PATH"), mySecondPath, "some/other/path")and be done with it.
I think it would put too much responsibility on the JoinList method to include error checking/validation of the paths also. Unless possibly verifying the paths provide use correct directory separators and valid characters .e.g '/' for linux and '\' windows, but again that dives into something else's responsibility, not directly JoinList's.
On Wednesday, January 9, 2013 8:01:59 PM UTC-8, speter wrote:On 10 January 2013 09:39, speter <spete...@gmail.com> wrote:
I don't think it is equivalent with Join(). In the case of Join(), elements can only contain '/' when they have been joined in some way previously. This is not the case when handling (lists of) directory names.
I think you're overthinking it, and I am sympathetic to minux's criticism. As API designers we should optimize for the common case, not the corner case. Adding AppendToList is going too far IMO. One of the main reasons for adding JoinList is for symmetry with Join, and the way Dave currently specifies it in his CL is very symmetrical. Doing some escaping (what escaping? what scheme?) on the path separator is not this function's responsibility.Symmetry is nice when possible but I don't think it works out in this case. There is ambiguity whether an "element" is a directory name or a list. Consider JoinList("", "/mybin"): if "" is a dirname, the result should be ":/mybin", if it is a list (PATH) it should be "/mybin".There is no ambiguity if JoinList only takes dirnames, and in that case I'd prefer it also did error check (no separators in dirnames). In that case, to append to PATH you could split+join or add a separate AppendToList.PeterAnother issue is empty directories. While it is not common for users to have the empty directory in their paths, those who do likely have it for a reason and it is generally not desirable to remove them.I can't think of any reason why this would ever be desirable. An empty path is meaningless on all operating systems that I know. Can you provide an example?Andrew
--
--
I have created https://codereview.appspot.com/7181047/ for SplitList, but build on Windows is broken right now (crypto/x509 test fails). Should I hg-mail it now or wait until build is clean?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.