Why is FileSystem's Path class private ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is FileSystem's Path class private ?

Damien Pollet
The class Path from FileSystem is documented as private… but it should be public, shouldn't it?

First hint is that it's named with a public name: (Path not FileSystemPath).

Then, consider the following use-case : if you have a file name in some config file (.ini, .toml…) then that's really a Path, not a resolved FileReference.

I'm not talking about RelativePath and AbsolutePath, those can be hidden away since Path provides the factory and DSL methods. IMHO they should still be renamed to a more private name.

--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Alistair Grant
Hi Damien,

On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
> The class Path from FileSystem is documented as private… but it should be
> public, shouldn't it?
>
> First hint is that it's named with a public name: (Path not FileSystemPath).
>
> Then, consider the following use-case : if you have a file name in some
> config file (.ini, .toml…) then that's really a Path, not a resolved
> FileReference.

The file name is implicitly attached to a file system, so it is
resolved (using Pharo terminology).  If you pass the path to a
program, e.g. an editor, it has enough information to be able to open
the file.

In Unix, everything is mounted on the root file system, so there's no
need to specify a file system.  Pharo's model allows for multiple file
systems, e.g. the disk, and multiple memory and zip file systems.

Path's by themselves don't provide much functionality - you can't
actually access the file or directory you think is represented by the
path; you have to know which file system the path is attached to.

It's the FileReference that associates the path and the file system,
and provides all the public interface.

HTH,
Alistair


> I'm not talking about RelativePath and AbsolutePath, those can be hidden
> away since Path provides the factory and DSL methods. IMHO they should still
> be renamed to a more private name.
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Damien Pollet
I understand that when you want to actually open and read/write files, you have to resolve them in a filesystem and that's what a FileReference is for.

But there are uses for file paths BEFORE you have a filesystem to resolve them in.

I was talking about a config file, in which some values are file names (sometimes absolute paths, sometimes relative). In a config file the paths are not resolved because the filesystem is not known; maybe I want to test the config file parser, and I don't actually have the matching files, or maybe they are in a memory filesystem.

Maybe I'm reading a Zip archive and I'm specifying a member of the archive (so the path does not point to an actual file on disk).

Maybe I'm writing a command-line argument parser, and some arguments are supposed to be file paths and I want to syntactically validate that aspect. Or I want to ensure that an argument is relative and not absolute. Or the argument is a relative path from an implicit origin (unspecified as far as the commandline parser is concerned); because the origin will be determined by application code.

In all those use cases, using FileReferences is just incorrect, as we're not talking about existing files, but about abstract places or navigation instructions in a hypothetical filesystem.


On 30 March 2018 at 16:57, Alistair Grant <[hidden email]> wrote:
Hi Damien,

On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
> The class Path from FileSystem is documented as private… but it should be
> public, shouldn't it?
>
> First hint is that it's named with a public name: (Path not FileSystemPath).
>
> Then, consider the following use-case : if you have a file name in some
> config file (.ini, .toml…) then that's really a Path, not a resolved
> FileReference.

The file name is implicitly attached to a file system, so it is
resolved (using Pharo terminology).  If you pass the path to a
program, e.g. an editor, it has enough information to be able to open
the file.

In Unix, everything is mounted on the root file system, so there's no
need to specify a file system.  Pharo's model allows for multiple file
systems, e.g. the disk, and multiple memory and zip file systems.

Path's by themselves don't provide much functionality - you can't
actually access the file or directory you think is represented by the
path; you have to know which file system the path is attached to.

It's the FileReference that associates the path and the file system,
and provides all the public interface.

HTH,
Alistair


> I'm not talking about RelativePath and AbsolutePath, those can be hidden
> away since Path provides the factory and DSL methods. IMHO they should still
> be renamed to a more private name.
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet




--
Damien Pollet
type less, do more [ | ] http://people.untyped.org/damien.pollet
Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Stephane Ducasse-3
I agree with you damien. This is the experience we are facing with pillar.
Manipulating fileReference is what pillar is doing and this is bad.

In addition the API of FileSystem is missing operations
using path such as copying a sub structure from a given level or path
to another structure at a different path.

On Fri, Mar 30, 2018 at 5:30 PM, Damien Pollet <[hidden email]> wrote:

> I understand that when you want to actually open and read/write files, you
> have to resolve them in a filesystem and that's what a FileReference is for.
>
> But there are uses for file paths BEFORE you have a filesystem to resolve
> them in.
>
> I was talking about a config file, in which some values are file names
> (sometimes absolute paths, sometimes relative). In a config file the paths
> are not resolved because the filesystem is not known; maybe I want to test
> the config file parser, and I don't actually have the matching files, or
> maybe they are in a memory filesystem.
>
> Maybe I'm reading a Zip archive and I'm specifying a member of the archive
> (so the path does not point to an actual file on disk).
>
> Maybe I'm writing a command-line argument parser, and some arguments are
> supposed to be file paths and I want to syntactically validate that aspect.
> Or I want to ensure that an argument is relative and not absolute. Or the
> argument is a relative path from an implicit origin (unspecified as far as
> the commandline parser is concerned); because the origin will be determined
> by application code.
>
> In all those use cases, using FileReferences is just incorrect, as we're not
> talking about existing files, but about abstract places or navigation
> instructions in a hypothetical filesystem.
>
>
> On 30 March 2018 at 16:57, Alistair Grant <[hidden email]> wrote:
>>
>> Hi Damien,
>>
>> On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
>> > The class Path from FileSystem is documented as private… but it should
>> > be
>> > public, shouldn't it?
>> >
>> > First hint is that it's named with a public name: (Path not
>> > FileSystemPath).
>> >
>> > Then, consider the following use-case : if you have a file name in some
>> > config file (.ini, .toml…) then that's really a Path, not a resolved
>> > FileReference.
>>
>> The file name is implicitly attached to a file system, so it is
>> resolved (using Pharo terminology).  If you pass the path to a
>> program, e.g. an editor, it has enough information to be able to open
>> the file.
>>
>> In Unix, everything is mounted on the root file system, so there's no
>> need to specify a file system.  Pharo's model allows for multiple file
>> systems, e.g. the disk, and multiple memory and zip file systems.
>>
>> Path's by themselves don't provide much functionality - you can't
>> actually access the file or directory you think is represented by the
>> path; you have to know which file system the path is attached to.
>>
>> It's the FileReference that associates the path and the file system,
>> and provides all the public interface.
>>
>> HTH,
>> Alistair
>>
>>
>> > I'm not talking about RelativePath and AbsolutePath, those can be hidden
>> > away since Path provides the factory and DSL methods. IMHO they should
>> > still
>> > be renamed to a more private name.
>> >
>> > --
>> > Damien Pollet
>> > type less, do more [ | ] http://people.untyped.org/damien.pollet
>>
>
>
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Eliot Miranda-2
In reply to this post by Alistair Grant
Hi Alistair,

> On Mar 30, 2018, at 7:57 AM, Alistair Grant <[hidden email]> wrote:
>
> Hi Damien,
>
>> On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
>> The class Path from FileSystem is documented as private… but it should be
>> public, shouldn't it?
>>
>> First hint is that it's named with a public name: (Path not FileSystemPath).
>>
>> Then, consider the following use-case : if you have a file name in some
>> config file (.ini, .toml…) then that's really a Path, not a resolved
>> FileReference.
>
> The file name is implicitly attached to a file system, so it is
> resolved (using Pharo terminology).  If you pass the path to a
> program, e.g. an editor, it has enough information to be able to open
> the file.
>
> In Unix, everything is mounted on the root file system, so there's no
> need to specify a file system.  Pharo's model allows for multiple file
> systems, e.g. the disk, and multiple memory and zip file systems.
>
> Path's by themselves don't provide much functionality - you can't
> actually access the file or directory you think is represented by the
> path; you have to know which file system the path is attached to.
>
> It's the FileReference that associates the path and the file system,
> and provides all the public interface.

But isn't the notion of a default file system (the root of the file system on the current machine, or the current image directory) so clear and natural that there be a public API that, by default, resolves past he against all that root?  It seems to me that the benefit of the convenience here is large.

>
> HTH,
> Alistair

Eliot,
_,,,^..^,,,_ (phone)

>
>
>> I'm not talking about RelativePath and AbsolutePath, those can be hidden
>> away since Path provides the factory and DSL methods. IMHO they should still
>> be renamed to a more private name.
>>
>> --
>> Damien Pollet
>> type less, do more [ | ] http://people.untyped.org/damien.pollet
>

Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Alistair Grant
In reply to this post by Damien Pollet
Hi Damien,

On Fri, Mar 30, 2018 at 05:30:52PM +0200, Damien Pollet wrote:

> I understand that when you want to actually open and read/write files, you have
> to resolve them in a filesystem and that's what a FileReference is for.
>
> But there are uses for file paths BEFORE you have a filesystem to resolve them
> in.
>
> I was talking about a config file, in which some values are file names
> (sometimes absolute paths, sometimes relative). In a config file the paths are
> not resolved because the filesystem is not known; maybe I want to test the
> config file parser, and I don't actually have the matching files, or maybe they
> are in a memory filesystem.
>
> Maybe I'm reading a Zip archive and I'm specifying a member of the archive (so
> the path does not point to an actual file on disk).

FileReferences are designed to handle this situation, e.g.  Let's say
I've zipped up my pharo directory:

(FileSystem zip: 'pharo.zip' asFileReference) open / 'pharo-local/play-cache/2018-03-29T21-49-20-403605+02-00.ph'

is perfectly fine.  Sending #contents to the resulting FileReference
will give me the expected result.



> Maybe I'm writing a command-line argument parser, and some arguments are
> supposed to be file paths and I want to syntactically validate that aspect. Or
> I want to ensure that an argument is relative and not absolute. Or the argument
> is a relative path from an implicit origin (unspecified as far as the
> commandline parser is concerned); because the origin will be determined by
> application code.

Good point.  FileSystem was written long before I got involved with
Pharo, so I don't know whether this situation was considered, and what
the expected approach was.

It would still be possible to use a FileReference to do the check -
there's nothing that says the path has to exist.

However that does seem to be stretching the usage, so I agree that using
Path makes sense in this case.


> In all those use cases, using FileReferences is just incorrect, as we're not
> talking about existing files, but about abstract places or navigation
> instructions in a hypothetical filesystem.


The comment in Path does say: "Normally users should not use me
directly."

So there is an out :-)  I think the comment is correct though - in most
cases the user should be dealing with FileReferences and not Paths.

Cheers,
Alistair




> On 30 March 2018 at 16:57, Alistair Grant <[hidden email]> wrote:
>
>     Hi Damien,
>    
>     On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
>     > The class Path from FileSystem is documented as private? but it should be
>     > public, shouldn't it?
>     >
>     > First hint is that it's named with a public name: (Path not
>     FileSystemPath).
>     >
>     > Then, consider the following use-case : if you have a file name in some
>     > config file (.ini, .toml?) then that's really a Path, not a resolved
>     > FileReference.
>
>     The file name is implicitly attached to a file system, so it is
>     resolved (using Pharo terminology).  If you pass the path to a
>     program, e.g. an editor, it has enough information to be able to open
>     the file.
>
>     In Unix, everything is mounted on the root file system, so there's no
>     need to specify a file system.  Pharo's model allows for multiple file
>     systems, e.g. the disk, and multiple memory and zip file systems.
>
>     Path's by themselves don't provide much functionality - you can't
>     actually access the file or directory you think is represented by the
>     path; you have to know which file system the path is attached to.
>
>     It's the FileReference that associates the path and the file system,
>     and provides all the public interface.
>
>     HTH,
>     Alistair
>
>
>     > I'm not talking about RelativePath and AbsolutePath, those can be hidden
>     > away since Path provides the factory and DSL methods. IMHO they should
>     still
>     > be renamed to a more private name.
>     >
>     > --
>     > Damien Pollet
>     > type less, do more [ | ] http://people.untyped.org/damien.pollet
>
>
>
>
>
> --
> Damien Pollet
> type less, do more [ | ] http://people.untyped.org/damien.pollet

Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Alistair Grant
In reply to this post by Eliot Miranda-2
Hi Eliot,

On Fri, Mar 30, 2018 at 12:57:25PM -0700, Eliot Miranda wrote:

> Hi Alistair,
>
> > On Mar 30, 2018, at 7:57 AM, Alistair Grant <[hidden email]> wrote:
> >
> > Hi Damien,
> >
> >> On 30 March 2018 at 14:59, Damien Pollet <[hidden email]> wrote:
> >> The class Path from FileSystem is documented as private??? but it should be
> >> public, shouldn't it?
> >>
> >> First hint is that it's named with a public name: (Path not FileSystemPath).
> >>
> >> Then, consider the following use-case : if you have a file name in some
> >> config file (.ini, .toml???) then that's really a Path, not a resolved
> >> FileReference.
> >
> > The file name is implicitly attached to a file system, so it is
> > resolved (using Pharo terminology).  If you pass the path to a
> > program, e.g. an editor, it has enough information to be able to open
> > the file.
> >
> > In Unix, everything is mounted on the root file system, so there's no
> > need to specify a file system.  Pharo's model allows for multiple file
> > systems, e.g. the disk, and multiple memory and zip file systems.
> >
> > Path's by themselves don't provide much functionality - you can't
> > actually access the file or directory you think is represented by the
> > path; you have to know which file system the path is attached to.
> >
> > It's the FileReference that associates the path and the file system,
> > and provides all the public interface.
>
> But isn't the notion of a default file system (the root of the file
> system on the current machine, or the current image directory) so
> clear and natural that there be a public API that, by default,
> resolves past he against all that root?  It seems to me that the
> benefit of the convenience here is large.

Right, #asFileReference does just that, e.g.:

'/home/alistair/.bashrc' asFileReference

and

'Pharo.image' asFileReference

will point to the expected places (in the second case, assuming that
Pharo.image is in your current working directory).

Cheers,
Alistair


> >
> > HTH,
> > Alistair
>
> Eliot,
> _,,,^..^,,,_ (phone)
>
> >
> >
> >> I'm not talking about RelativePath and AbsolutePath, those can be hidden
> >> away since Path provides the factory and DSL methods. IMHO they should still
> >> be renamed to a more private name.
> >>
> >> --
> >> Damien Pollet
> >> type less, do more [ | ] http://people.untyped.org/damien.pollet
> >
>

Reply | Threaded
Open this post in threaded view
|

Re: Why is FileSystem's Path class private ?

Stephane Ducasse-3
In reply to this post by Alistair Grant
> The comment in Path does say: "Normally users should not use me
> directly."
>
> So there is an out :-)  I think the comment is correct though - in most
> cases the user should be dealing with FileReferences and not Paths.
>

I guess that I wrote it when I started to write comment on this library.
But it can be totally wrong.

Stef