Skip to content

Should it be considered “idiomatic KDL” to use node names as arbitrary keys? #549

@tmke8

Description

@tmke8

The following example KDL file is contained in this repository:

package {
    name kdl
    version "0.0.0"
    description "The kdl document language"
    authors "Kat Marchán <kzm@zkat.tech>"
    license-file LICENSE.md
    edition "2018"
}

dependencies {
    nom "6.0.1"
    thiserror "1.0.22"
}

Everything within package makes sense to me, but I was surprised to see how the dependencies are specified. The node names within dependencies are used as names of the packages. In XML, the analog would be to use custom tags for the dependencies. I would have expected it to be defined more like this:

dependencies {
    crate nom "6.0.1"
    crate thiserror "1.0.22"
}

(aside: in the case of Cargo.toml, you could actually convey other important information with the node name:

dependencies {
    // `registry` means the crate is found on crates.io or whatever registry is configured
    registry nom "6.0.1"
    // dependency from git
    git regex "https://github.com/rust-lang/regex.git" tag="1.10.3"
    registry hello_utils "0.1.0"
    // specify a path as well for `hello_utils` to use for local development
    path hello_utils "../hello_utils"
}

)

On reflection, the TOML syntax for Cargo.toml uses the same kind of slightly-surprising trick of using a table with arbitrary names for specifying the dependencies:

[dependencies]
nom = "6.0.1"
thiserror = "1.0.22"

However, with TOML you at least get the side benefit that this ensures that there are no duplicates in the crate names. KDL doesn't care whether you duplicate node names within dependencies, so we don't get that side benefit.


So, I lean towards not considering this pattern idiomatic KDL, but, well, you maybe shouldn't care what I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions