3 ms·
> There is a big difference between configuration language formats and programming languages. You're right! But in my opinion the difference is that a configur
by lexicality 3y ago
> There is a big difference between configuration language formats and programming languages.
You're right! But in my opinion the difference is that a configuration file should have a default state that could be written to disk and loaded with no change in behaviour.
eg you can set `feature = "on"` or `feature = "off"` and if you don't set either it's the same as writing `feature = "off"`.
Having a secret third thing of `feature = null` should be outlawed and I'm glad TOML doesn't encourage it
- the_mitsuhiko 3y agoThere is a secret third thing called "feature not in file" and most TOML implementation encourage it as "key not in file" is typically returned as `null` or `None`. That's how so many TOML files in practice end up with all these secret values. It's also particularly odd in lists where I have seen `["foo", "bar", {}]` show up in the real world with `{}` being used as a replacement value for null.
- lexicality 3y agoIn my experience (Python and Rust) missing keys are errors, not silently converted to None: In [1]: example = {"foo": None} In [2]: print(example["foo"]) None In [3]: print(example["bar"]) --------------------------------------------------------------------------- KeyError Traceback (most recent call last) Cell In[3], line 1 ----> 1 print(example["bar"]) KeyError: 'bar' In [4]: print(example.get("bar", "sensible default")) sensible default If configuration values were arbitrarily nullable I would either need to deal with the possibility of nulls ending up anywhere in my program (back to The Billion Dollar Mistake) or have to have checks on parsing to say which fields are nullable or not. I acknowledge people have done silly things regarding missing keys already - but I think they should be discouraged from continuing to do so, not enabled.
- donaldstufft 3y agoHow is checking for null any different than checking for the right type in general in TOML?
- rascul 3y ago> In my experience (Python and Rust) missing keys are errors, not silently converted to None: In Rust it's possible to deserialize to an Option. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b6e808c8e6a0d2ec197aabe7012ab315 https://play.rust-lang.org/?version=stable&mode=debug&editio...