The specific impetus for pitching these protocols is the proposal to move Combine’s TopLevelDecoder
and TopLevelEncoder
protocols to the standard library.
The protocols introduced by Combine don’t require userInfo
dictionaries, even though they are required by Decoder
and Encoder
. Why? Because having a userInfo
dictionary isn’t actually relevant to serialization. Any type might arguably benefit from having such a property, but it would be ridiculous to add that requirement to all of them.
It is widely agreed that the most “Swifty” design patterns make heavy use of composition, especially protocol composition: good protocols require only what is directly relevant to their intended meaning, and inherit from other protocols as necessary.
If Decoder
requires userInfo
to be a concrete type, then it becomes mutually exclusive with other protocols that require a different type. While that is now set in stone, it would be better for future protocols to avoid such requirements.
That’s the point of my examples: keeping protocols separate allows for more flexibility, especially when those writing the protocols are not the same people implementing them. And in the case of userInfo
, that’s more or less the entire point.