If, for example, a program needed a work directory, there are several ways that the directory could be specified:
As a global program constant like WORKDIR = '/tmp/work'
On the command line as an argument: this_prog --workdir=/tmp/work
As an environment variable: env WORKDIR=/tmp/work this_prog
In a configuration file: WORKDIR /tmp/work
If any combination of the above methods were to be used then what should take precedence?
I would suggest commandline argument over environment variable over configuration file over in-program constant. Based on how easy it would be to make a change to the value.
I would use the following precedence, highest to lowest:
command line argument
environment variable
user config file, e.g. ~/.myconfig
system-wide config file, e.g. /etc/myconfig
hard-coded default, e.g. global program constant
If appropriate, e.g. in a GUI program, or an interactive wizard-style program, you can also interactively ask the user for settings; that clearly should be highest precedence of all.