Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-01-13 10:41:26


christopher diggins wrote:
> Nonetheless consider the following psuedo-program (which does model a
> lot of software):
>
> void Fu(string s) {
> cout << s;
> }
>
> string Bar() {
> string ret;
> cin >> ret;
> return ret;
> }
>
> string Transform(string s) {
> string ret(s);
> // do some stuff
> return ret;
> }
>
> void DoTransform() {
> while (!cin.eof()) {
> Fu(Transform(Bar()));
> }
> }
>
> int main() {
> DoTransform();
> return 0;
> }

IMO, this is how a more realistic example would look like:

void consume( string const & s, ostream & out )
{
    out << s;
}

string produce( istream & in )
{
    string ret;
    in >> ret;
    return ret;
}

// Transform as above

void do_transform( istream & in, ostream & out )
{
    while( !in.eof() )
    {
        consume( Transform( produce(in) ), out );
    }
}

int main()
{
    do_transform( cin, cout );
}

This is just a reflection of the general "globals are bad" principle.


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