From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2003-10-19 05:01:04
"Daniel Frey" <daniel.frey_at_[hidden]> wrote in message
>s.trim() is what IMHO would be an intuitive interface to changes s's
>state. Sadly, it's not possible to provide it. It's the old question
>whether or not a function should modify its arguments. Of course you are
>right that the STL uses a different notion, but that's not the one and
>only argument as you seem to suggest. From my experience (and I would
>like to hear whether others share this view), users don't expect x to
>change when they write f(x).
they should not expect that to be the only way to read f(x). Think of
several C library functions; think of Pascal procedures. It's beyond me how
you can state that.
> The most problematic portion of the
> current interface is in fact, that it allows you to write:
> std::string s = "Hello, world!";
> std::string t = trim( s ); // Ouch!
well, in this case, nothing is trimmed. If the user has read the "Usage"
section he will easily
know that trim etc changes the argument.
> It's IMHO very hard to find these kinds of errors...
I really don't know. I think the hardest errors I had to debug was index
beyond array bounds from some C library.
I and why is it an error? What about this error:
trim( s ); // bug: s is not changed
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk