Don’t use environment variables for configuration
101–110 of 296 posts
Re: Don’t use environment variables for configuration
#102Re: Don’t use environment variables for configuration
#103Re: Don’t use environment variables for configuration
#104first_argument = 1;
second_argument = 2;
int three = add_numbers();
This is, I trust you all agree, terrible. This approach is plain wrong.
I agree, but I don't think everyone agrees. Just have a look at the apple APIs, their configuration options are all objects you have spend time configuring, then pass as an argument. I don't know why everything with Apple development beats around the bush. It's almost too object oriented.
To be clear, Apple is more like this:
let argument = Argument()
argument.first = 1
argument.second = 2
let addRequest = AddRequest()
adder.add_numbers(with: arguments)
let mathRequest = MathRequest()
mathRequest.perform([addRequest])
if let results = addRequest.results {
// Do something with your results.
}And yes though, Apple development makes me feel smart when I solve something that should've been documented.
Re: Don’t use environment variables for configuration
#105Easy fix (if it's the shared, mutable state which bugs you): * Create one class responsible for ingesting env vars at startup. * Call it from main, and abort early with nice messages if it fails to read something. * Now you have a nice (preferably immutable) class which guarantees the config is in a 'good state', and is self-documenting because it lists all the keys it uses to lookup env vars with.
Re: Don’t use environment variables for configuration
#106Yes, if your OS is some unversal JS machine, then JSON would be better, if it is Lisp machine, then you would use S-expressions, but on Unix machine, environment/args are way to go.
There are two realistic alternatives - config files and arguments. They have each their own niche, where environment is somehwere between them.
Arguments are better for one-shot setting, not for some setting used always. You can use 'alias' to define shortcuts that always add some argument, but that is definitely more cumbersome.
Config files are good for always/default setting, but are too rigid. Changing config files is equivalent of changing global variable in code, it has system/user-wide effect. While i can just change environment in this one shell and it will affect just commands executed from that shell. Also, config files are much harded to be manipulated from scripts, and use different syntax for each tool.
Perhaps the ideal tool would allow every option to be set/changed from config file, environment and argument.
Re: Don’t use environment variables for configuration
#107Re: Don’t use environment variables for configuration
#108I have a pet peeve about this attitude. These methods are being used for decades and well understood with all their advantages and disadvantages. One day, someone comes and tells that it's bad and considered harmful , and happily tells the only right way to do it . A flame war ensues then. I'm all for moving things forward and evolution, but can't we take a milder stance and move forward in a more peaceful way? Attac…
> These methods are being used for decades and well understood with all their advantages and disadvantages. Just because something has been used for decades does not make it good - for example, avoidable mutable state. And it certainly does not make it well-understood - as a consultant the number of brain frying environment variable configurations I've had to deal with which no permies could tell me anything about de…
I'm not calling this is good with the persistence of the original author. I tell that it's one of the realities that we have, and instead of burning it with torches, why not build better conventions around it with better attitude and language?
Maybe we can try: "Instead of burying all config under environment variables, why not try doing it like this?", and slowly build something better, step by step. Nothing is inherently good or bad, but can be abused. So the abuse of environment variables as a shortcut needs to stop, one may say and I'd agree, and may also volunteer to help to build a better thing.
But, shunning it with anger and shouting "I'm the one who knows all right things!" sure creates backlash, like here.
All in all, I'm against the attitude, not the idea of improving a situation.
> Yes, some things are bad and are actively harmful.
It might be, but even your solution might not be right. Why the attitude?
> unstructured programming using gotos. Would you like to go back to that?
Did that on some older, limited hardware, and it was fun. It was not OK by today's standards, but I had to. I'll do it again if it's the only thing I can do to work on that particular hardware again.
> But perhaps you are not a programmer?
I just design algorithms and develop scientific applications which run on HPC clusters, nothing fancy.
> It's not a "de-facto standard", it's simply bad.
I didn't say it's good. I say it's a fact. I'm not disagreeing on its bad sides. I'm not OK with the attitude.
Re: Don’t use environment variables for configuration
#109there's an astonishingly silly GitHub issue thread linked in the comments of the post: https://github.com/ninja-build/ninja/issues/1482
Re: Don’t use environment variables for configuration
#110If you're a heathen like me, you sometimes store JSON configuration in environment variables https://mitchum.blog/how-to-store-json-in-an-environment-var...
Then, of course, you have the fun of Azure Application Configuration and KeyVaults - which are fine once set up and your app is happy with them.