← Back to context

Comment by SPBS

3 years ago

TOML sucks for list of tables simply because they intentionally crippled inline tables to only be able to occupy one line. For ideology reasons ("we don't need to add a pseudo-JSON"). Unless your table is small, it's going to look absolutely terrible being all crammed into one line.

https://github.com/toml-lang/toml/issues/516

The official way to do list of tables is (look at how much duplication there is)

  [[main_app.general_settings.logging.handlers]]
    name = "default"
    output = "stdout"
    level = "info"

  [[main_app.general_settings.logging.handlers]]
    name = "stderr"
    output = "stderr"
    level = "error"

  [[main_app.general_settings.logging.handlers]]
    name = "access"
    output = "/var/log/access.log"
    level = "info"

vs

  handlers = [
    {
      name = "default",
      output =  "stdout",
      level = "info",
    }, {
      name = "stderr",
      output =  "stderr",
      level = "error",
    }, {
      name = "access",
      output =  "/var/log/access.log",
      level = "info",
    },
  ]

I would still reach for TOML first if I only needed simple key-value configuration (never YAML), but for anything requiring list-of-tables I would seriously consider JSON with trailing commas instead.

I see the point and this is certainly a drawback of TOML but for me this is something of a boundary case between configuration and data.

When configuration gets so complicated that the configuration starts to resemble structured data I tend to prefer to switch to a real scripting language and generate JSON instead.

for this reason I couldn't see a CI platform ever seriously consider TOML

(someone may point out to me a CI platform that relies on TOML—which I welcome)

  • Rust is built on TOML. For better or worse.

    • Do you mean Cargo? Because Cargo is not a CI system. You never embed shell commands in a Cargo.toml.

      If you need to program complex logic to build a crate, you don’t write TOML. You write a build.rs file in actual Rust.

      1 reply →