Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-17 09:12:38


From: "Beman Dawes" <bdawes_at_[hidden]>
> Here is the approach that seemed to work well in various initial uses of
> the library:
>
> First, nail down a base directory, either from user input:
>
> path base( argv[1], system_specific );
>
> or from the initial directory:
>
> path base( initial_directory() );
>
> From this point on, all path references are relative to "base". (A more
> complex program might have several base directory paths, named
> appropriately, and perhaps store them in an object.)
>
> For example, if you want to see if base contains a file called "foo",
> write:
>
> if ( exists( base << "foo" ) ) ...
>
> For files or directories referenced more than once, create a path variable
> and then use it:
>
> path bar_path( base << "bar" );
>
> create_directory( bar_path );
> if ( bar_path << "foo" ) ...
>
> Notice that we don't care whether:
>
> * base is absolute or relative.
> * the operating system even has a concept of relative paths.
> * the operating system has a concept of current directory.
> * the operating system allows the current directory to be changed.
> * and, finally, we don't need a concept of "root" (since that is
> dealt with by either initial_directory() or user input.
>
> I consider this to be much better design than the traditional approach,
> because it avoids global variables like current directory, and because it
> avoids a lot of portability pitfalls.

I've been trying to understand your point of view but I still don't see how
you avoid the current directory with the above.

Consider the case (assume POSIX for clarity) where the user input is "foo".
Your base path is relative, and as such, it inherently depends on the
current directory. In order for the program to function as intended, "foo"
must be interpreted as relative to initial_directory() even if the current
directory changes while the program is running, but the library does not
provide a way to do that.

In effect, the library works as intended only if the current directory
doesn't change. But if the current directory is assumed to never change, it
is no longer "evil" to provide a way to access it, as it is a global
constant.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk