Component initialization in constructor vs separate configure function #3590
csmith608
started this conversation in
Pattern Request
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Pattern
Explain why the pattern in F Prime breaks with the standard C++ pattern "RAII" to use configure functions rather than initializing the component in the constructor.
Rationale
Explanation that was provided to me:
In F Prime we do a configure call because one-argument constructors work much better with FPP as FPP can then instantiate the component without custom code to supply arguments. If you change the interface past a single argument, then FPP cannot automatically construct it for you and this would require require phase-code to fix that. Initializing a component in the constructor uses the standard C++ pattern "RAII" which says that a class holding a resource should be invariant over the life of the class (e.g. from construction to destruction). https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization . This is inconsistent with a deferred configure call. While we like RAII patterns a lot, they are inconsistent with a Global singleton (i.e. an F prime component as normally constructed in global space) requiring non-global input (e.g. CLI arguments). For this and the above reason of zero-arg constructors, we use the deferred configure pattern.
Beta Was this translation helpful? Give feedback.
All reactions