My case for null
#1040
Replies: 1 comment 1 reply
-
Part of your first use case is perplexing. If you "unset a default", then you have no default value. I believe what's implied is that there is, in fact, another layer of defaults below
You could describe what you're doing as either:
In either case, it seems more like an artifact that emerges from your merge strategy. The simplest solution to me seems to be don't set it in " |
Beta Was this translation helpful? Give feedback.
-
Motivating use-case 1
I come from the JavaScript ecosystem where we have a package called config.
I really like the pattern it implements. I end up setting up my projects like this:
Now,
default.ts
contains a complete 'development' configuration, and is included in VCS.production.ts
contains a partial configuration of overwrites that are applied conditional on theNODE_ENV
environment variable, and is included in VCS.local.ts
contains a partial configuration of overwrites that are always applied, but is not included in VCS.config
library will deep-merge the structures exported from these files in a consistent, predictable order.In practise, this is good for various reasons ...
default.ts
acts as living documentation for the overwrite keys I can choose to add tolocal.ts
,production.ts
.default.ts
toproduction.ts
when I make changes.local.ts
without affecting collaborators.local.ts
without exposing them via my VCS.Notably, though, for this pattern to work, I sometimes need to use
null
orundefined
values inproduction.ts
in order to 'unset' values defined bydefault.ts
.So when I came to trying to implement this pattern for a Python project using
.toml
files in place of.ts
, I was fairly dismayed when I found out I can't havenull
values in.toml
files!Motivating use-case 2
Say I have an 'optional' value which I load from a
.toml
file.As long as the defined value for
foo
is not null-ish, it is obvious to any contributor to my project simply by looking in the config file that they can amend the value offoo
to have some effect on the project's behaviour.But if the defined value for
foo
is null-ish, I can eitherfoo
from the config fileBoth of these make it considerably less obvious to an arbitrary individual that
foo
is something they can amend the value of.Other remarks
null
andundefined
are simply 'sentinel' values roughly meaning 'the absence of a value'.If we want to get really silly, we could say TOML already supports
null
-ish values ...Strategy 1: 'flags'
foo
->null
becausefoo_is_null
baz
->"qux"
becausenot baz_is_null
Strategy 2: bring your own sentinel value
select an arbitrary value that is unlikely to ever show up in common use ...
and use it to represent
null
valuesfoo
->null
because its value is exactly the chosen sentinel valuebaz
->"qux"
because its value is not the chosen sentinel valuefin.
since
null
-ish values are clearly 100% supported already (/s), what difference does adding anull
keyword make? it would save people the effort of runningopenssl
or duplicating all the keys in their files :0)I want to be arguing over
null
/nil
/none
/undefined
, not about whether TOML needsnull
!Beta Was this translation helpful? Give feedback.
All reactions