Application settings
Jacob Carlborg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 10 01:50:26 PDT 2017
On 2017-07-07 21:40, FoxyBrown wrote:
> What's the "best" way to do this? I want something I can simply load at
> startup in a convenient and easy way then save when necessary(possibly
> be efficient at it, but probably doesn't matter).
>
> Simply json an array and save and load it, or is there a better way?
I would say it depends on what kind of application and which platforms
it supports. For GUI applications there's usually a native way to store
application settings, which will be different on different platforms.
For example, on macOS the NSUserDefaults class (Swift and Objective-C)
is used, which will eventually store the settings in the plist format [1].
For CLI tools it seems quite common to store the settings in a file or
directory in the user's home directory call .<app>rc where <app> is the
name, or short name, of the application. The actual format of these
files vary between applications, platforms and which language they're
implemented in. For example, it seems pretty common for tools written in
Go to use the TOML format [2]. In D, the corresponding format would be
SDLang [3].
> Ideally, I'd like to store the settings as part of the binary to keep
> everything together but that poses a few issues I think.
I would say again that this depends on the kind of application and the
platform.
[1]
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/UserDefaults/Introduction/Introduction.html
[2] https://github.com/toml-lang/toml
[3] http://sdlang.org
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list