Boost logo

Boost :

Subject: [boost] [Review:Contract] Some questions
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-08-26 05:16:20


Hi,

First of all, thanks Lorenzo for your work on pre-processor programming.
With this library, you have showed to me how far the pre-processing can
go in terms of expressiveness.

I have some questions before doing a complete the review:

= C++11 compatibility =

* Does the library use c++11 features when available? I was thinking
e.g. on the emulated virtual specifiers. BTW, I think the "new" virtual
specifier was removed from the standard, but maybe I'm wrong.
* I think the library don't allow to declare C++11 specific
classes/function. E.g
   * variadic templates
   * noexcept functions
   * constexpr functions
   * class/function attributes

BTW, I have not see any example using exception specifications using
'throws'. Does the library support them?

Could you confirm? and if not, could you tell us if you have a plan to support them?

= Postconditions result =

"Postconditions can access the function return value by declaring a
variable of type |auto| and assigning it to the |return| keyword (the
variable name is arbitrary but |result| is often used)."

What prevent the library to the use of return instead of an auto variable

         postcondition( // Postconditions.
             auto old_value = CONTRACT_OLDOF value, // Old value(s).
             value == old_value + 1, // Assertion(s)...
             return == old_value
         )

instead of

         postcondition( // Postconditions.
             auto result = return, // Result value.
             auto old_value = CONTRACT_OLDOF value, // Old value(s).
             value == old_value + 1, // Assertion(s)...
             result == old_value
         )

=Constant assertions =

I would expect that the old are always const so the following

             postcondition(
                 auto old_even = CONTRACT_OLDOF even,
                 auto old_odd = CONTRACT_OLDOF odd,
                 // `[old_]even` and `[old_]odd` all `const&` within assertions.
                 const( even, old_even ) even == old_even + 2,
                 const( odd, old_odd ) odd == old_odd + 2
             )

should be rewritten without loss of semantics as

             postcondition(
                 auto old_even = CONTRACT_OLDOF even,
                 auto old_odd = CONTRACT_OLDOF odd,
                 // `[old_]even` and `[old_]odd` all `const&` within assertions.
                 const( even ) even == old_even + 2,
                 const( odd ) odd == old_odd + 2
             )

= Oldof =

As the old of value must be declared using a variable, using a specif oldof keyword that will replace

                 auto old_size = CONTRACT_OLDOF size(),
by

                 oldofold_size = size(),

could simplify the syntax. What do you think?

Some minor points:

* Why do you use( void ) instead of () in the functions without parameters? e.g.

     public: bool empty ( void ) const { return vector_.empty(); }

Some suggestions:

* Use 2 spaces indentation instead of 4 could reduce the width of the page, in particular when you use several columns.
* The use of'int const' as return type is verbose and could be replaced by just int.

Best,
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk