5 ms·
> Environment variables is exactly this: mutable global state. Not really; environment variables can't be externally changed once they're passed in. If it wer
by elihu 6y ago
> Environment variables is exactly this: mutable global state.
Not really; environment variables can't be externally changed once they're passed in. If it were true mutable global state, some external process could change their value while a program is running. Or the program could change the value of the environment variable in the shell that launched it. Either of those would be horrifying.
In other words, environment variables could be worse. They could also be better. My main objection to environment variables is that they're not a discoverable interface. Ideally, it should be possible to find out what environment variables a program accepts without running the program (or grepping the source code for "getenv"), and in most cases it should be possible to enumerate the valid values.
Environment variables are just one of many things about they typical POSIX / ANSI C interface that have been around so long people don't even question it anymore.