DEV Community

loading...

Which YAML style do you prefer?

Nicolas Mahe
Co-founder at Liteflow.com
・1 min read

Hey guys,

I'm working on a workflow project that uses YAML files to define workflows.

We are starting to design a new version with the goal of improving the syntax to make it easier for developers to write workflows.

One of the main new feature is to include YAML file using the following syntax: ${ file('workflows/foo.yml') }.

I would like to know which of the following YAML style do you prefer.

Map style

# main.yml
name: my first app
workflows:
  foo-workflow:
    steps:
      - ...
  bar-workflow: ${ file('workflows/bar.yml') }
# workflows/bar.yml
steps:
  - ...
  • workflows is a map
  • workflow's name defined only in the main file

Array style

# main.yml
name: my first app
workflows:
  - name: foo workflow
    steps:
      - ...
  - ${ file('workflows/bar.yml')}
# workflows/bar.yml
name: bar workflow
steps:
  - ...
  • workflows is an array
  • workflow's name defined is the workflow's file

Discussion (4)

Collapse
katiekodes profile image
Katie • Edited

Hmmm -- YAML preserves the ordering of maps, so you could get away with the first, but it seems to me that anything where you're literally calling things "first," "second," "third," etc. implies a list. Especially if you might later end up having to parse it into JSON or into programming languages where dicts aren't ordered.

But that's mostly if you think your numbers will stretch beyond, say, 10.

If you know it's more like "primary" and "backup," you could probably get away with either. What do your teammates like?

Also, you might want to add a "discuss" tag to this.

Collapse
nicolasmahe profile image
Nicolas Mahe Author

Thanks for your comment!

Hmmm -- YAML preserves the ordering of maps, so you could get away with the first, but it seems to me that anything where you're literally calling things "first," "second," "third," etc. implies a list.

The workflows are not actually ordered. My bad for using “first” and “second”, it brings confusion to the discussion. I will edit now.

What do your teammates like?

They prefer the map version but I want to make sure it’s the best ;)

Also, you might want to add a "discuss" tag to this.

Tag added. Thanks for the suggestion.

Collapse
dz4k profile image
Deniz Akşimşek

Should two workflows be allowed to have the same name? If not, map style.

Collapse
nicolasmahe profile image
Nicolas Mahe Author

Good point!
Workflows cannot have the same name.
Thanks for this simple yet efficient argument.

Forem Open with the Forem app