16748, “e-kayrakli”, “Path-related methods on ‘file’ type”, “2020-11-19T21:24:56Z”
We have the following methods on file
defined in the Path
module:
file.absPath
file.getParentName
file.realPath
file.relPath
But the following functions in the Path
module doesn’t define symmetric
methods on file
:
splitPath
normPath
basename
This raises the following questions:
- Why do we have methods on file for some Path functions but not for some?
- Should these be in the Path module?
Few strategies that seem to have supporters:
-
Move
file.absPath
andfile.realPath
to IO, make them independent of
Path
by storing relevant information in thefile
type itself. -
Remove them altogether. This would make users do
use Path; absPath(file.path);
, for example. -
Keep them in the Path module, but re-arrange what is available on
file
: it
doesn’t make much sense to havegetParentName
(ordirname
) onfile
, but
notbasename
, for example. That doesn’t mean we should add
file.splitPath
, however.
Notes:
-
Motivation for having methods on
file
can be relying on different
implementations and information stored infile
. However, the current
implementation offile
doesn’t lend itself to that readily. So, there may be
more implementation on that side for that to happen.One similar motivation is to avoid using cwd or other means that can be
race-y. -
@ben-albrecht noted that Python’s file type doesn’t have path-specific methods
Path module reference: https://chapel-lang.org/docs/master/modules/standard/Path.html