4 ms·
I love using cap'n'proto to store configurations. It's really slick. + Type safe since you define the schema for every part of your configuration. + Ridiculou
by vlovich123 6y ago
I love using cap'n'proto to store configurations. It's really slick.
+ Type safe since you define the schema for every part of your configuration.
+ Ridiculously easy to read/understand (writing has a small ramp curve to build the muscle memory).
+ Type system is very flexible & rich (lists, maps, unions), supports generics (for built-in & custom types) & everything is neatly composable (including constants that reference constants).
+ The config compiles down to a minimal binary file.
+ You can have arbitrary configurations in 1 file (you compile a specific constant to a file so each configuration you want is just 1 constant value you define in the schema).
+ The binary file can be converted back to text using standard cap'n'proto tools so it's easy to double-check the config you're deploying.
+ Perfect backward/forward support for the configuration as long as you follow the rules (similar to protobuf/flatbuffers) since you have to define the schema for your constants.
+ Loading the config file from any data source (disk, network) is trivial and for on-disk usages you could mmap the struct to get even better performance (only the parts of the config you access would get paged in).
+ Supports a variety of languages. While the RPC stuff has a bit less adoption, the parts needed for configuration should be available in the most popular languages (I think the only missing language generator is Swift).
The only negatives are:
- You do have to define the schema for your config
- There's a single upfront cost to integrate cap'n'proto into your build system if you're not using CMake.
Neither feel like prohibitive negatives though. If you're looking at strong typing, why not go all the way & make sure that your entire config has a strongly typed structure to it? Not just that some field is an int also that there's certain specifically named fields & that accessing these fields in a strongly-typed languages will result in build errors if you forgot to change something.