What's the best way (and location) to store non-BLOB settings?
On Windows, it seems acceptable to use the registry. In my opinion, the registry was a poorly-devised system, and instead a simple text file in the Users\Username\AppData
directory should be preferred. This is easier to back up, less dangerous for users to modify, and easier to clean up.
On Linux and most Unixes, The preferred location is /home/user/.config/appname
for user-specific settings and /etc/
for global (system-wide) settings. The less-preferred (but acceptable) location for user settings is ~/.appname
, but this is generally falling out of favor. These files should be user-editable, so a human-readable format is always preferred.
I disagree with most people that XML is an acceptable format for storing non-blob data. It is, in my opinion, an overwrought and excessively complex format for what usually ends up being very small pieces of structured data. I prefer to see files in YAML, JSON, ASN.1, name=value pairs, or similar formats. Having too much syntax makes it too easy for a user to mess up and leave the file in an invalid format.
Should we follow each system default or have a unified solution?
That is entirely up to you, but keep some things in mind:
- Platforms like *nix have strict limitations on which locations are writable. More strict than Windows. So:
- The only place you should write to anything is in the user's home directory.
- Unless your application is a system service; in which case, all mutable data files should be written in
/var/
. Nonmutable data files should be kept in your app directory in /usr/share/
or /usr/local/share/
or /opt/
- Configuration files in
/etc/
should never be written to by the application when it is running, even if it has write access to them. /etc/
should be the repository for default behaviors and nothing else.
- Plan for your application to be installed in one of three places:
/usr/local/
, /opt/appname
, or /home/username/appname
.
- Blobs should be stored alongside other configuration files if they are to be changed. It is generally preferable to use a user-editable format, so something like SQLite or Berkeley DB is preferred (since there are command-line tools for each), but not required.
- On Windows, your applications should only ever write in the User directory. The standardized location for data files is
Users\User\AppData
. Nowhere else seems acceptable.
- On Mac OS X, your application settings should be stored in
~/Library/Preferences
along with all of the other applications' plist files. plist
seems to be the preferred format, but you'll want to double-check with the Apple guidelines.
And what's the best portable way?
There is no "best," to be honest. There are only platform-specific limitations and expectations. My recommendation is to stick with platform-specific means, even if it means writing more code.