.yaml, .toml, etc?

  • simonced@lemmy.one
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    A lot of good answers but I would add one note:

    • use a format that supports comments, and JSON is not one of those…
          • sfera@beehaw.org
            link
            fedilink
            arrow-up
            1
            ·
            1 year ago

            Don’t worry, I wouldn’t do things like this in JSON. Nevertheless, it can be very useful to have comments along with configuration values, for example to explain the actual values (not their purpose) and why they were chosen. That’s information you can’t add to the code which processes the values.

  • Skyzyx@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    Whatever. Comments are helpful, which makes pure JSON a poor choice. JSON5 or JSON-C are better, but linting and static analysis are important to every form of code, so make sure that what you use for that will understand your syntax.

    My current preference is generally TOML, but I’ve started dabbling with custom HCL2 DSLs. (I write a lot of Go and Terraform.)

  • vrkr@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    No reason to go beyond simple key-value format like dotenv or just env variables. If you need more structure then maybe you are confusing configuration with state and this is not really the same thing.

  • Edo78@feddit.it
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    It really depends. I usually prefer json. It’s easily understandable from humans and from machines, it doesn’t depends on indentation and above everything else I like it very much 🤣

  • spartanatreyu@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    It depends what you need your configuration file to be:

    Need a well defined easy to understand concrete configuration file?

    • Use .toml. It was made to be both human and computer friendly while taking special attention to avoid the pitfalls commonly found in other configuration files by explicitly stating expected types around commonly confused areas.

    Need a simple to implement configuration file?

    • Use .json. It’s famous for being so simple it’s creator “discoverer” could define it on a business card.

    Need an abstract configuration file for more complicated setups?

    • Use .ncl. Nickle allows you to define functions so that you can generate/compute the correct configuration by changing a few variables/flags.
    • argv_minus_one@beehaw.org
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Please do not use YAML. It’s a syntactic minefield. It also doesn’t allow tab indentation, which is supremely irritating.