|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-04-26 11:50:29
"Justin M. Lewis" <boost_at_[hidden]> writes:
> You're missing the point. Personally I see the need for out and
> in/out params. While some of you may not like them, I use them, as
> do others. The question then becomes, when reading my code, would
> you rather see
>
> f(x,y,z);
> or
> f(out(x), in_out(y), z);
>
> Would you rather the outcome be obviously clear? Or would you
> rather have to track down the source? The same thing goes for if
> you were reading code that someone else wrote who used my library,
> which way would you prefer it? Would you prefer to have to have a
> complet understanding of every single function call made in a
> program or would you prefer that as much information as possible is
> given at the point of invocation?
I prefer some degree of abstraction and information hiding.
> You're welcome to go out of your way to write your code to never use
> out or in/out params, although I think that's impractical in a lot
> of cases, that doesn't mean that everyone else is going to do the
> same.
I didn't say "never", I do it only when it's idiomatic and hard to
misunderstand.
I'm reluctant to accept your idea for two reasons:
1. I think liberal use of out parameters is bad practice, and I have
no interest in a library which makes bad practice more palatable.
But if you're bound and determined to do it, by all means clarify
by whatever means neccessary.
2. I'd hate to see a facility like that applied where mutable
references are already idiomatic, e.g:
out(cout) << 3;
out(x) += 2;
std::swap(in_out(x), in_out(y));
Techniques designed to increase safety and clarity should usually
come with simple and uniform rules for when they are applied.
-Dave
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk