In simple cases I can see right away which direction to go. If I’m passing a working directory to my program, and it’s the same for the vast majority of the runs, make it a configuration variable.
Conversely if I have to change a configuration for every single run of the program than it should probably be an argument.
What happens if things live in a grey area? What should I pay attention to when deciding one or the other?
NOTE: I’m specifically working on a console program that might be daemonized down the road. I’m interested in this question in general, however.
0
Nothing precludes command-line arguments from being used when starting a daemon, or configuration files from being used in interactive mode.
The general approach that works well and a lot of programs use is to have a list of prioritized ways to set program options:
- Defaults
- Global configurations (/etc or HKLM in the registry)
- Local configurations (home directory or HKCU in the registry)
- Environment variables
- Program arguments
- Options set while the program is running interactively
The program will start at step 1 and set values in each step, overriding previous values if applicable.
There is no reason this should work differently based on the program running interactively, in the background, at a command prompt, in a GUI, or as a daemon.
This is the way most experienced users and administrators will expect a program to work.
5