You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initialized fields was a paradigm introduced to metadata as a way to ignore unset values in metadata so that we could generate minimal metadata protocol strings.
This paradigm has been widely adopted across the codebase, mostly done in #337. It was a massive PR, so we were focused on other things and paid less attention to the paradigms used.
The problems with introducing this paradigm across the SDK:
You are forced to use the setters defined by the library or must set the initialized fields bits yourself
This means the optimal way to use these structs becomes object oriented, rather than data oriented or procedural. Which also contributes to some of the later problems
Struct members which should not have unset values are now unset by default.
Initializing or setting values in a struct directly has side-effects and can't be done safely.
Passing modifiable pointers to struct members around also has side-effects for the same reasons.
More code to write in order to use the library, more code to maintain
An example of this is doing a notify:update which was previously ~5 function calls is now ~20
And most of these ~20 function calls can produce errors, which means you also have to write error handling an extra ~12 times.
We require extra private functions, which means separating them from the public interface, further complicating code maintenance. This also means more private header files if we want to test, introduce .c files which have both public & private headers associated with them.
The solution for most of these things is to have sensible unset values for optional struct members:
For pointers, we have NULL to represent this.
For numerical values: often space in the negative range or 0 for ports.
Booleans: are actually a byte so they have space for unset value
Packed booleans: use 2 bits, one for initialized, one for value
The text was updated successfully, but these errors were encountered:
Initialized fields was a paradigm introduced to metadata as a way to ignore unset values in metadata so that we could generate minimal metadata protocol strings.
This paradigm has been widely adopted across the codebase, mostly done in #337. It was a massive PR, so we were focused on other things and paid less attention to the paradigms used.
The problems with introducing this paradigm across the SDK:
notify:update
which was previously ~5 function calls is now ~20.c
files which have both public & private headers associated with them.The solution for most of these things is to have sensible unset values for optional struct members:
For pointers, we have NULL to represent this.
For numerical values: often space in the negative range or 0 for ports.
Booleans: are actually a byte so they have space for unset value
Packed booleans: use 2 bits, one for initialized, one for value
The text was updated successfully, but these errors were encountered: