Thinking about why I go through this paroxysm of disgust whenever I encounter a toolchain that depends on environment variables. Like Modules or modulefiles(1). Like many CAD tools.
This morning it struck me: they are a dominant meme. An evolutionarily stable strategy.
Not because environment based tools are better.
But because cleanly written stuff,like I try to write, can be called pretty safely from anywhere. Whereas stuff that does what I consider unclean environment modifications cannot be called so easily from other code. It can call other code, but it is hard to be called from other code. So there is a tendency for users to just give in, and write in csh (since csh in so often the language associated with such environment dependent tools).
Sure, you can try to write code that prints the environment and which then gets called. However, this only catches the UNIX environment - modulefiles(1) rely on sideeffects in the extended shell environment, shell functions and aliases. You could print these, but would have to parse them to pass to a different language, or at least reread them if passing to a later compatible shell.
Bandaid.
The best way to work with such tools is to start a persistent subprocess, pass it commands, and interpret the results. Expect style. Coroutines. Which is doable, but is more complex than order function calls / UNIX style subprocess invocations.
No comments:
Post a Comment