Boost logo

Boost :

Subject: Re: [boost] [Review] Boost.Contract Review Period Extended
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-09-06 13:33:16

On Thu, Sep 6, 2012 at 9:57 AM, ecyrbe <ecyrbe_at_[hidden]> wrote:
> 2012/9/6 Lorenzo Caminiti <lorcaminiti_at_[hidden]>
>> On Thu, Sep 6, 2012 at 7:05 AM, ecyrbe <ecyrbe_at_[hidden]> wrote:
>> > I vote NO for the inclusion of the contract library in Boost.
>> Thanks a lot for submitting a review!
> I think my tone could seem a litle rude. I forgot to congratulate you for
> the long a hard work you have done on this library.

Your tone is good, don't worry and thanks :)

>> > I do agree that the work done is really interresting, but i don't think
>> > that using MACROS are the way to add this functionnality.
>> Sure this'd be ideal but... do you have any suggestion on how to
>> implement Contract Programming within C++ without using macro? I
>> thought about this problem a lot (that of "not using macros" was even
>> an original goal when I started creating the library 4+ years ago) but
>> I had to conclude it's impossible... For example (and there are more
>> examples like this) how would you implement the following CP
>> requirements without macros?
>> 1. If a function is not public, don't check class invariants.
>> 2. Subcontracting.
> I would like to comment on this. I know that making a Eiffel like
> integrated contract programming in c++ in not feasible.
> But i think that an original one, maybe based on functors could be possible
> (may be i'm totally wrong).
> something declared like a boost::function<Signature>, but using something
> like :
> boost::contract<Signature> push_back;
> and has to be initialized like this :
> push_back(precondition_functor,
> real_push_back_functor,postcondition_functor);
> and if any invariant is declared :
> push_back(precondition_functor,
> real_push_back_method,postcondition_functor, invariant_functor);
> I know that it's not easy to implement functors in c++03 , but in c++11
> with lambdas, you could initialize this really easily, and still have a
> nice library.
> For c++03, you still could provide a macro frontend to allow users to
> implement this easily, but having a more native way to do it in c++11 would
> be awesome.

Also let's keep in mind that contracts should be specified at the
declaration site. In any case, this is the best I was able to do
without using macros (rev 0.3.490 of the lib that still supported the
non-macro API):

Essentially this used function pointers (I guess you could similarly
use functors) to pass to the lib the functions that checked
pre/post/etc so the lib could check. This was abandoned because of the
large amount of boiler-plate code that users have to program,
including repeating the function signature a few times to program the
pre/post/body/etc functions to pass to the lib. Also subcontracting
relied on the user repeating bases classes everywhere making the code
very hard to maintain. Finally, disabling the contract code on
compilation (i.e. removing the pre/post/body/etc functions/functors)
required the user to manually program #ifdef and the all thing got
pretty ugly.

> What i want to say, is that, i would have said YES to this macro frontend
> if a nice c++11 compliant backend was exposed to those that don't want to
> use macros.
> These are only thoughts.
> Thanks for reading.


Boost list run by bdawes at, gregod at, cpdaniel at, john at