New Issue: Path-related methods on 'file' type

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:

  1. Move file.absPath and file.realPath to IO, make them independent of
    Path by storing relevant information in the file type itself.

  2. Remove them altogether. This would make users do use Path; absPath(file.path);, for example.

  3. Keep them in the Path module, but re-arrange what is available on file: it
    doesn’t make much sense to have getParentName (or dirname) on file, but
    not basename, 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 in file. However, the current
    implementation of file 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