DUB: json or sdl?

jfondren julian.fondren at gmail.com
Wed Sep 22 11:11:52 UTC 2021


On Wednesday, 22 September 2021 at 10:19:18 UTC, Ki Rill wrote:
> Out of curiosity, which one do you use in your dub projects and 
> why do you prefer one over another?
>
> For example, I use json. Simply because when I see `sdl`, I 
> think of `SDL2` graphics library.
>
> What's your reason?

Reason to prefer JSON:

1. dub is stricter about the format, and will complain about 
errors for SDL would result in values being silently ignored.

2. you want something like a 2008 Perl install to be able to do 
something with your dub.json files, instead of writing a D 
program.

3. you hope that a glacier of increasing dub.json files will 
eventually tear out the roots of dub having more than one config 
format

4. you have a phobia about malicious comments getting injected 
into your dub.sdl files

5. you used jq and liked it to the point of finding other formats 
intolerable

Reasons to prefer SDL:

1. comments in dub.sdl files,

2.

```d
#! /usr/bin/env dub
/+ dub.json: {
    "dependencies": {
        "sumtype": "~>0.10.0",
     },
     "dflags": ["-betterC"],
}
+/

vs.

#! /usr/bin/env dub
/+ dub.sdl:
    dependency "sumtype" version="~>0.10.0"
    dflags "-betterC"
+/
```

dub converts SDL to JSON for ~/.packages/ , and the same code 
might be used to convert SDL documentation to JSON, so I think 
the main problem of multiple dub configuration formats (that it's 
more of a chore to talk about dub configuration) is not that bad.

> On Wednesday, 22 September 2021 at 10:45:41 UTC, bauss wrote:
> Json because it's a consistent format across environments 
> outside of D, unlike sdl which is basically only used by D and 
> only by dub really.

With JSON you do not have to remember what an array or a hash 
looks like, but that doesn't tell you that the `"dflags"` key has 
an array of strings rather than looking like `"dflags": 
"-betterC",`

You have to look up what dub expects either way, so the 
consistency fails to help with the most frustrating part of dub 
configurations, which is writing them in the first place.


More information about the Digitalmars-d mailing list