
Lorenzo Caminiti wrote:
Hello,
I would like to renew the request for all of you to express an opinion between OPTION 1 and 2 below. I am NOT asking you to understand Boost.Contract. On the contrary, the less you know about Boost.Contract the more your input is valuable for me.
Please just indicate which syntax between OPTION 1 and 2 you would like the most (or dislike the least ;) ) to see in your header files.
On Sat, Mar 20, 2010 at 10:54 AM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
OPTION 1: The function declaration is programmed using the usual C++ syntax just before the CONTRACT_FUNCTION() macro.
template<typename T> class myvector {
CONTRACT_INVARIANT( ({ ... }) )
public: void push_back(const T& element) // Usual C++ push_back() declaration. CONTRACT_FUNCTION( (class) (copyable)(myvector) (public) (void) (push_back)( (const T&)(element) ) (precondition)({ ... }) (postcondition)({ ... }) (body)({ ... }) )
... };
OPTION 2: The CONTRACT_FUNCTION() macro automatically programs also the function declaration.
template<typename T> class myvector {
CONTRACT_INVARIANT( ({ ... }) )
public: // No usual C++ push_back() declaration here. CONTRACT_FUNCTION( (class) (copyable)(myvector) (public) (void) (push_back)( (const T&)(element) ) (precondition)({ ... }) (postcondition)({ ... }) (body)({ ... }) )
... };
Thanks a lot! Lorenzo
Well, knowing very little about Boost.Contract except what I glean from the mailing list messages, I'd prefer OPTION 2, but with some minor tweaks. E.g., can the public/private/protected specification just be whatever the access is as the point of the macro invocation? I'd also prefer "(( const T&, element ))" to "( const T& ) ( element )", and perhaps a usage recommendation would be to #define the "( class ) ( copyable ) ( myvector )" to some preprocessor symbol so that you don't have to type it out for every CONTRACT_FUNCTION invocation. Perhaps you can have a variant of CONTRACT_FUNCTION that just uses some predefined macro to get the information encapsulated in "( class ) ( copyable ) ( myvector )" ? This might alleviate the parentheses problem, e.g., OTHER_CONTRACT_FUNCTION( public, void, push_back, (( const T&, element )) ) Also, are there going to be more design decision queries sent to the mailing list where "less knowledge is better"? If so, I will do my damnedest to remain ignorant ;) - Jeff