Boost logo

Boost :

From: Greg Colvin (Gregory.Colvin_at_[hidden])
Date: 2002-11-18 16:46:01


At 01:32 PM 11/18/2002, Rob Stewart wrote:
>From: "Andrei Alexandrescu" <andrewalex_at_[hidden]>
>>
>> I recently reached the conclusion that taking a parameter by const reference
>> just to make a copy of it inside the function is a "lie". The signature
>> says: "I don't need a value! A reference to a const is all I need!" and the
>> code says: "The first line of this function makes a copy!" There will be a
>> section in my upcoming article entitled "The Lying const". Taking const& T
>> as arguments in /any/ function when you actually *do* need a copy chokes the
>> compiler (and Zuto) and practically forbids them to make important
>> optimizations.
>
>If there are lost optimizations, I might be persuaded to change
>my modus operandi, but I really dislike by value parameters. The
>reason is that I like to know the value given by the caller
>throughout the function. When I want to start with the caller's
>value and then modify it, I make a copy.
>
>When I read code that modifies the arguments, I find the code
>confusing as I can never know the value in that variable unless I
>inspect the entire function. While we all know functions should
>be kept relatively short, they aren't always, and long functions
>exacerbate the problem. IOW, by value arguments reduce code
>clarity.

And I really dislike by-reference parameters. I like functions
to be free of side effects, and especially of non-obvious side
effects.


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