[Python-ideas] Subpaths [was Re: PEP 428 - object-oriented filesystem paths]

Steven D'Aprano steve at pearwood.info
Tue Oct 9 02:28:13 CEST 2012


Nick,

I've come to the conclusion that you are right to prefer a named method
over an operator for joining paths. But I think you are wrong to name that
method "subpath" -- see below.


On 09/10/12 05:39, Nick Coghlan wrote:
> On Mon, Oct 8, 2012 at 11:53 PM, Steven D'Aprano<steve at pearwood.info>  wrote:
>>> "p.subpath('foo', 'bar')" looks like executable
>>> pseudocode for creating a new path based on existing one to me,
>>
>>
>> That notation quite possibly goes beyond unintuitive to downright
>> perverse. You are using a method called "subpath" to generate a
>> *superpath* (deeper, longer path which includes p as a part).
>
> Huh? It's a tree structure. A subpath lives inside its parent path,
> just as subnodes are children of their parent node. Agreed it's not a
> widely used term though - it's a generalisation of subdirectory to
> also cover file paths.

I believe you mentioned in an earlier email that you invented the term
for this discussion. Quote:

     I made it up by using "make subpath" as the reverse of
     "get relative path".

Unfortunately subpath already has an established meaning, and it is the
complete opposite of the sense you intend: paths are trees are graphs,
and the graph a->b->c->d is a superpath, not subpath, of a->b->c:

a->b->c is strictly contained within a->b->c->d; the reverse is not true.

Just as "abcd" is a superstring of "abc", not a substring. Likewise for
superset and subset.

And likewise for trees (best viewed in a monospaced font):

a-b-c
  \
   f-g

One can say that the tree a-f-g is a subtree of the whole, but one cannot
say that a-f-g-h is a subtree since h is not a part of the first tree.


> They're certainly not "super" anything, any more than a subdirectory
> is really a superdirectory (which is what you appear to be arguing).

Common usage is that "subdirectory" gets used for relative paths: given
path /a/b/c/d, we say that "d" is a subdirectory of /a/b/c. I've never
come across anyone giving d in absolute terms. Now perhaps I've lived a
sheltered life *wink* and people do talk about subdirectories in absolute
paths all the time. That's fine. But they don't talk about "subpaths" in
the sense you intend, and the sense you intend goes completely against
the established sense.

The point is, despite the common "sub" prefix, the semantics of
"subdirectory" is quite different from the semantics of "substring",
"subset", "subtree" and "subpath".




-- 
Steven



More information about the Python-ideas mailing list