Boost logo

Boost :

From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2006-09-14 12:45:25


Hi Rene!

On 9/14/06, Rene Rivera <grafikrobot_at_[hidden]> wrote:
> To take some of Dean's examples:
>

[snipped my examples]

>
> I would expect to more native syntax:
>
> ====
> int my_value = 0;
> ensure( 10 == my_value );
> ensure( 9 != my_value );
>
> char * my_pointer = NULL ;
> ensure( NULL == my_pointer );
> ensure( NULL != my_Pointer );
> ====
>

This is also similar to:

int my_value = 0;
assert(10 == my_value);
assert( 9 != my_value);

char * my_pointer = NULL;
assert( NULL == my_pointer );
assert( NULL != my_pointer );

Which is precisely what BDD wants to get away from.

> Hence why I don't see the point of BDD when I'd rather have a contract
> definition framework.
>

What a potential for having a BDD framework in place, is that you can
have your system level tests (or acceptance tests) written out in
english (in a text file) and generate your acceptance tests from that
document. In your text file you'd probably see:

Protocol Definition
    client sends "GET /index.html" to the server; server response is a string
    server response should equal "HTTP/1.1\r\n"

And then you can come up with a pretty trivial tool (perhaps with
Spirit or maybe Boost.Build) to generate something like the following:

void protocol_definition {
   std::string server_response = client.sends("GET /index.html",
server); // ignored to the
   value(server_response).should.equal("HTTP/1.1\r\n");
};

Then that allows you to re-write your acceptance tests according to
the requirements, and be able to programmatically generate a program
from that document format. Think of it as metaprogramming, but this
time not just with templates and preprocessor directives. ;)

That's just one of the potentials. Another is having to be able to
communicate to other programmers a document derived from code, using
almost the same process as outlined above.

Of course, there is also the "it reads better" or "it reads naturally
to me" factor, which is I think is one of the key things to remember
when designing readable interfaces. :-)

-- 
Dean Michael C. Berris
C++ Software Architect
Orange and Bronze Software Labs, Ltd. Co.
web: http://software.orangeandbronze.com/
email: dean_at_[hidden]
mobile: +63 928 7291459
phone: +63 2 8943415
other: +1 408 4049532
blogs: http://mikhailberis.blogspot.com http://3w-agility.blogspot.com
http://cplusplus-soup.blogspot.com

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