Merging Settings at Different Priorities
Settings often combine default, environment, and user values. Define which supplied entry wins for a shared key.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a small override
Defaults may set font size 14 and theme gray. A user choice of font size 16 changes only that key. Preserve gray and record the chosen precedence. Dictionary keys and values make the merge about entries with matching keys.
Check nested settings as a separate rule
If a default font record contains size and family, replacing the entire font entry with a size-only record drops the family. A documented nested merge may keep it where appropriate. Function contracts should specify which rule callers rely on.[1]
Resolve only the keys a later layer provides
Suppose defaults are {"limit": 20, "timeout": 10} and a user supplies {"limit": 0}. If zero means unlimited, the effective limit is zero while the timeout remains ten. A truthiness-based merge would substitute twenty. Decide separately whether an explicit null clears a setting. Preserve each key's source if people need to diagnose results assembled from several layers. See unset, empty and zero values.
Define whether merging descends into nested records
If defaults hold both width and height inside a display section, a shallow replacement with only a new width can discard height. An explicit per-field merge preserves height when the configuration schema calls for that behavior. Lists may need entirely different semantics, such as replacement rather than concatenation. Test a nested partial override and an unknown key. See shallow container copies.