I am creating a configuration file for my application. To do it, I decided to use YAML for its simplicity and reliability.
I am currently designing a special part of my application: In this part, I have to list and configure all datasets I want to use in a module. To do that I wrote this :
// Other stuff
datasets:
rate_variation:
name: Rate variation over time # Optional
description: Description here # Optional
type: POINTS_2D
options:
REFRESH_TIME: 5 # Time of refresh in second
frequency_variation:
name: Frequency variation over time
description: Description here # Optional
type: POINTS_2D
But, after some reflection, I have some doubts about it. Because maybe something like this is better :
datasets:
- id: rate_variation
name: Rate variation over time # Optional
description: Description here # Optional
type: POINTS_2D
options:
REFRESH_TIME: 5 # Time of refresh in second
- id: frequency_variation
name: Frequency variation over time
description: Description here # Optional
type: POINTS_2D
I use the ID to identify each dataset in my scripts (two datasets must have a different id) and generate output files for each of them. But now, I really don't know what is the best solution...
What would you recommend to use? And for what reason?
ddconfig formatddconfig format
ddconfig)Scenario: Developer graille_stentiplub is creating a configuration file format for use with YAML.
Special considerations: graille_stentiplub wants an easy way to determine when to use lists vs mappings.
the following is a simple config file using YAML ddconfig format
dataroot:
file_metadata_str: |
### <beg-block>
### - caption: "my first project"
### notes: |
### * href="//home/sm/docs/workup/my_first_project.txt"
### <end-block>
project_info:
prj_name_nice: StackOverflow Demo Answer Project
prj_name_mach: stackoverflow_demo_001a
prj_sponsor_url: https://stackoverflow.com/questions/54349286
prj_dept_url: https://demo-university.edu/dept/basketweaving
dataset_recipient_list:
- [email protected]
- [email protected]
- [email protected]
dataset_variations_table:
- dvar_id: rate_variation
dvar_name: Rate variation over time # Optional
dvar_description: Description here # Optional
dvar_type: POINTS_2D
dvar_opt_refresh_per_second: 5 # Time in seconds
- dvar_id: frequency_variation
dvar_name: Frequency variation over time
dvar_description: Description here # Optional
dvar_type: POINTS_2D
The entire data structure is nested under a toplevel key called dataroot (this is optional).
dataroot key makes the YAML structure more addressible but is not necessary.dataroot as a root-level directory.The entire data structure consists of a YAML mapping (aka dictionay) (aka associative-array).
dataroot (or else a toplevel key if dataroot is omitted).There are different types of mapping keys:
_str) indicates that the mapped value is a string (aka scalar) value._list) indicates the mapped value is a list (aka sequence)._info) indicates the mapped value is mapping (aka dictionary) (aka associative-array)._table) indicates the mapped value is a sequence-of-mappings (aka table)._tree or _struct) indicates a composite structure with support for one or more nested parent-child relationships.ddconfig format coincides nicely with many different contexts and tools._list mapping consists of a sequence of scalar-value items with no nesting._info mapping consists of a scalar-key and a scalar-value (name-value pairs) with no nesting._table mapping is simply a sequence of _info mappings._tree composite data structure.ddconfig _info mapping as a single record from a standard table in a relational database.ddconfig _table mapping as a standard table in a relational database.ddconfig format works well with YAML anchors and aliases._info mappings can be easily converted to a _table mapping by way of aliases._info mappings can be combined together into another _info mapping by way of YAML merge keys.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With