Replies: 1 comment 5 replies
-
To make a few assumptions above explicit:
I think these are big assumptions worthy of further discussion elsewhere and I won't comment on them here. I agree that absence, presence and determinism ("optionality") need to be defined in the specification and made explicit, regardless of how they are implemented:
I therefore also agree that authors must be able to specify a value's absence. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In order to satisfactorily define optionality, we must revisit some foundational requirements (some of which we have informally discussed previously). In the following list, I am assuming that the term "configuration source" refers to the means by which a user can supply configuration values to the configuration system.
Requirements
Some of the following requirements establish background for optionality, and others are the logical consequence of those foundational requirements.
Empty values
Here are the requirements we must establish or reassert:
This is the foundational concept of configuration.
This capability is not consistently present in MP Config and is not possible in the SmallRye Config implementation, which was the topic of some controversy; we have the ability to rectify this architecturally with Jakarta Config and the consensus has been consistent in that we wish to do so.
Missing values
Therefore, a configuration source should be consulted for a value only if the value is implicitly missing from all higher-priority configuration sources.
In this way, the definition of the term "empty value" and the term "missing value" are made distinct for the purposes of this specification as desired.
Note well: This is distinct from the ability to restore a value to its default or from the ability to provide an empty value such as an empty list or string). Furthermore, an explicitly missing value is not implicitly missing (i.e. it overrides the value of any lower-priority configuration source which may exist).
This establishes the exact interaction between empty, missing, and default values.
Lists
While there is still much to sort out about lists of simple values, with this model I think it is safe to establish that any list (or set or sequence or array etc.) of simple values cannot contain any missing values. If a member of such a list would correspond to a missing value, that value shall be skipped and not count towards the content of the list in any way.
Implications
Config sources
In order to meet these requirements, configuration sources must be able to react to a query in one of the following three ways:
This should be possible through conscientious API design; I would add the following constraint as well:
Note that practically speaking, this means that while the primary specification APIs (as well as any specified implementations of interface methods) should never return
null
to help avoid user error, the configuration source (which will likely be an extensible API in the final specification) should embracenull
as a representation for a missing value for that very same reason: otherwise, we will have to specify the behavior of the system whennull
is returned from a user configuration source implementation, which is not ideal.Syntax
In order to support the requirement to distinguish empty values from missing values, the syntax for an explicitly missing value must be distinct from the syntax for an explicitly empty value of any given type (e.g. string, array, list) for all configuration sources. While rich formats like YAML might have idiomatic ways to do this (for example, using the special YAML-specific
null
/~
value to indicate explicitly missing), file formats such as the properties file format or sources such as system properties or environment properties might have a harder time expressing this in a useful way without the use of some kind of special value syntax.We have (at least) the following options to deal with this:
Alternatives
Instead of supporting the idea of differentiated explicitly missing, implicitly missing, and "empty" value behaviors, we could try another approach.
Use the SmallRye Config method
One alternative could be to drop the difference between explicitly missing and "empty" values, using an empty string as a canonical (unconverted) representation for explicitly missing. This has all of the previously discussed downsides, but on the other hand, the model is internally consistent.
Eliminate the concept of explicitly missing values
We could simply decide to make it impossible for the user to override a value with an explicitly empty value. This approach has a few downsides:
Beta Was this translation helpful? Give feedback.
All reactions