This is a high-level question and I am sure there is no universally correct answer but I really would like to learn more about the different ways of doing this:
How does one best deal with parameters in a program?
To clarify, I am talking about all the values (e.g., of class variables) that the program requires to execute certain tasks. In many cases, one would like to use different values in different scenarios. So how to best deal with these (user-supplied) value?
Some approaches:
- Simply define them in the code and change them as required (i.e.,
change source code) - Use a special class to specify all parameters and use static imports
- Implement an interface with all the parameters specified (and implement interface accordingly)
- Pass them as command line arguments
- Use a (text) file and load them (using, e.g., a class to access the values after loading)
I know that some of these are bad practice so please also list the pros and cons based on your experience.
I would put in the sources only real constants that are never changed. Having to rebuild a program because of a new input is not really necessary
The other option is to make them available with options or arguments (command line or GUI)
If your use case requires different arguments almost every time you use your program choose the command line option (with optional defaults). This will force the user to think about them
If the parameters rarely change use an option storage (text file, xml file, database whatever is best suited)