Re: Application settings

2017-07-10 Thread Jacob Carlborg via Digitalmars-d-learn

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 .rc where  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


Re: Application settings

2017-07-08 Thread Timothee Cour via Digitalmars-d-learn
I use protocol buffers (using dproto) for this, storing my settings in
either text or wire format. Advantages: type-safety with fwd/backward
compatibility (unlike json which requires dynamic field access, eg
with dproto you get errors at compile time instead of runtime),
supports comments (although can be done w preprocessor on json config
file), supports more types than json (especially binary without
needing to base64 encode).


On Sat, Jul 8, 2017 at 11:35 AM, Seb via Digitalmars-d-learn
 wrote:
> On Saturday, 8 July 2017 at 05:00:45 UTC, bauss wrote:
>>
>> On Friday, 7 July 2017 at 22:52:22 UTC, FoxyBrown wrote:
>>>
>>> On Friday, 7 July 2017 at 20:45:36 UTC, Moritz Maxeiner wrote:

 On Friday, 7 July 2017 at 19:40:35 UTC, FoxyBrown wrote:
>
> [...]


 "best" always depends on your specific use case. I use json files via
 asdf [1]

 [1] https://github.com/tamediadigital/asdf
>>>
>>>
>>>
>>> Seems like quite a heavy package for what I need. I just want to write a
>>> AA to disk and load it, ultimately.
>>
>>
>> Then I would go with INI, because you'll ultimately just have key-value
>> pairs.
>>
>> https://code.dlang.org/packages/baussini (Pretty old but should still work
>> just fine.)
>
>
> There is also inifiled: https://github.com/burner/inifiled (used for
> Dscanner for example)


Re: Application settings

2017-07-08 Thread Seb via Digitalmars-d-learn

On Saturday, 8 July 2017 at 05:00:45 UTC, bauss wrote:

On Friday, 7 July 2017 at 22:52:22 UTC, FoxyBrown wrote:

On Friday, 7 July 2017 at 20:45:36 UTC, Moritz Maxeiner wrote:

On Friday, 7 July 2017 at 19:40:35 UTC, FoxyBrown wrote:

[...]


"best" always depends on your specific use case. I use json 
files via asdf [1]


[1] https://github.com/tamediadigital/asdf



Seems like quite a heavy package for what I need. I just want 
to write a AA to disk and load it, ultimately.


Then I would go with INI, because you'll ultimately just have 
key-value pairs.


https://code.dlang.org/packages/baussini (Pretty old but should 
still work just fine.)


There is also inifiled: https://github.com/burner/inifiled (used 
for Dscanner for example)


Re: Application settings

2017-07-07 Thread bauss via Digitalmars-d-learn

On Friday, 7 July 2017 at 22:52:22 UTC, FoxyBrown wrote:

On Friday, 7 July 2017 at 20:45:36 UTC, Moritz Maxeiner wrote:

On Friday, 7 July 2017 at 19:40:35 UTC, 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?


"best" always depends on your specific use case. I use json 
files via asdf [1]


[1] https://github.com/tamediadigital/asdf



Seems like quite a heavy package for what I need. I just want 
to write a AA to disk and load it, ultimately.


Then I would go with INI, because you'll ultimately just have 
key-value pairs.


https://code.dlang.org/packages/baussini (Pretty old but should 
still work just fine.)


Re: Application settings

2017-07-07 Thread FoxyBrown via Digitalmars-d-learn

On Friday, 7 July 2017 at 20:45:36 UTC, Moritz Maxeiner wrote:

On Friday, 7 July 2017 at 19:40:35 UTC, 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?


"best" always depends on your specific use case. I use json 
files via asdf [1]


[1] https://github.com/tamediadigital/asdf



Seems like quite a heavy package for what I need. I just want to 
write a AA to disk and load it, ultimately.


Re: Application settings

2017-07-07 Thread aberba via Digitalmars-d-learn

On Friday, 7 July 2017 at 19:40:35 UTC, 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?


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.


Setting are not kept in binary (usually). Normally the installer 
would take care of creating a folder somewhere with a 
JSON/XML/SQlite file which stores settings.


Re: Application settings

2017-07-07 Thread Moritz Maxeiner via Digitalmars-d-learn

On Friday, 7 July 2017 at 19:40:35 UTC, 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?


"best" always depends on your specific use case. I use json files 
via asdf [1]


[1] https://github.com/tamediadigital/asdf


Application settings

2017-07-07 Thread FoxyBrown via Digitalmars-d-learn
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?


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.





Re: Application settings

2017-07-07 Thread Cym13 via Digitalmars-d-learn

On Friday, 7 July 2017 at 19:40:35 UTC, 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?


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 think you're better off with a simple file in a format like 
JSON or INI yeah. Simpler is better.


I don't see any easy way to save the configuration in the binary 
and would find it more troublesome than anything as an user as 
having the configuration appart means I can easily compare it 
between computers and track its changes etc.


I don't think you need to worry about performances, after all 
it's only loaded once and the config would have to be *really* 
big for it to have a noticable loading time.