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.absPathfile.getParentNamefile.realPathfile.relPath
But the following functions in the Path module doesn’t define symmetric
methods on file:
splitPathnormPathbasename
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.absPathandfile.realPathto IO, make them independent of
Pathby storing relevant information in thefiletype 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
filecan be relying on different
implementations and information stored infile. However, the current
implementation offiledoesn’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