Search code examples
user-preferences

Best way of handling user settings in a program


I want to know what are the best ways/practices of handling user settings in a program. I'm writing a program and want to allow users to save settings which can be loaded automatically as soon as the program starts. I'm not just asking for codes, but the best practices of handling such as how to handle the settings at run time, should I need to create an object such as UserSettings (I'm using Java)? Which format is best for saving the settings (XML/JSON?)? Is it good to have the file format human readable? what are the things that I should take care of? I like to hear the thoughts/advices of some professional stackoverflow users out there.


Solution

  • If your users will roam from computer to computer then having user settings in a database or some centralised repository makes sense.

    Otherwise, a locally-saved, human-readable .INI (with named sections) or a .XML file.

    If using a .XML file, try to avoid making it too 'dense', and sprinkle with appropriate comments.