Hacker News new | ask | show | jobs
by umvi 29 days ago
> durations like 30s are real values, so nobody has to guess the unit of timeout: 30

Pet peeve of mine, but I would argue that it's better to always keep units baked into the key.

If you have:

   timeout_s: 30
Then unit information will never be lost, because the unit is always marshalled as a part of the key name and you don't have to worry if the target language has a duration type or not.

If you have:

   timeout: 30s
Then unit information probably won't be lost, but could in the following scenarios:

- Target language doesn't have duration types (looking at the list - Ruby?)

- If you ever need to convert to/from a data format without durations like JSON

So basically you have to use SOML across your entire stack and always use languages that have native duration types, and also you have to be careful never to convert SOML to/from JSON (which is highly likely if you ever have to interface with external APIs). Do any of those things and you'll likely run into a unit confusion scenario at some point.

But there are going to be lots of configs that won't have native type like size. Again, just include units in key:

    max_size_bytes: 30000000
In conclusion, my opinion is to KISS by including units in the key name and by sticking to bool/number/string primitives, hence why I almost always use JSON for everything (though if I could be granted one wish, it would be for JSON spec to allow for dangling commas)
1 comments

`timeout: 72h` reads better than `timeout_s: 6220800`
I agree, but there's a tradeoff which is that not every language/data format supports duration types:

Ruby:

    config = SOML.load_file('config.soml', symbolize_names: true)
    config[:timeout] # what are the units? uses SOML::Duration non-Ruby type
Even worse if you ever convert to/from JSON. My opinion is that config files should be as dumb and simple as possible. If you want humans to be able to read/write fancy stuff like "72h" for config, build a UI layer for the human to use in front of the config. Then they can click a little calendar icon to select the date. The backing config uses dumb iso 8601 string instead of a magical date type baked into the config language.