The new std.process is ready for review

Lars T. Kyllingstad public at kyllingen.net
Mon Feb 25 23:08:33 PST 2013


On Monday, 25 February 2013 at 20:21:55 UTC, Vladimir Panteleev
wrote:
> On Monday, 25 February 2013 at 20:09:14 UTC, Lars T. 
> Kyllingstad wrote:
>> Exceptions are designed to handle exceptional cases.  A 
>> missing environment variable isn't exceptional, it is 
>> commonplace.
>
> I disagree. I don't know your uses cases, but as far as I can 
> see, if the program expects the variable to be present in the 
> environment, then it is no different from a missing file which 
> the program expects to be present, or malformed user input.
>
>> That would depend on the application.
>
> Could you provide a specific example? It's difficult to discuss 
> the merits of either approach without some use cases.

Well, take Phobos, for instance.  Besides std.process, there are
two places where environment/getenv is used: std.file.tempDir()
(POSIX version) and std.path.expandTilde().  None of them throw
if the variables in question don't exist, they both take some
default action instead.


> As I see, there are two major cases:
>
> 1) The program expects a variable to be set. An example of this 
> is COMSPEC / SHELL. These variables ought to be set on any 
> system, so the user is not expected to verify this himself. The 
> variables not being set is an exceptional sitation.
>
> 2) A variable may or may not be set, such as the case of 
> passing additional options via the environment (such as 
> INCLUDE, or LD_PRELOAD). The program will take specific action 
> if the variable is not set, such as pretending it is empty, or 
> defaulting to some other setting like one in a configuration 
> file.
>
> It seems like your approach caters to the second situation 
> exclusively. I've mentioned the problems of applying this 
> approach to the first situation in my previous post.

What if the variable is set, but empty?  Is that very different
from the situation where it doesn't exist at all?  In my opinion,
when it comes to environment variables, no.

You mention 'rm -rf $FOO/$BAR' as a "classic catastrophic bug" in
shell scripts.  This is just as much a problem if FOO and BAR are
simply empty, and throwing from opIndex() won't help you with
that.  You still have to test for empty(), which would *also*
test for null.

Lars


More information about the Digitalmars-d mailing list