Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-07-06 01:15:45


Jody Hagins <jody-boost-011304_at_[hidden]> writes:

> Joel, I am really interested to know why you prefer the functional
> approach in C++, a language which offers both options.
>
>
>> Me, I prefer the immutable and functional approach:
>>
>> to_upper(to_lower(to_upper(rng)))
>
>
> Blech. What are the overwhelming reasons for having purely immutable
> interfaces in C++?

In C++ or any language, functional interfaces tend to make code
clearer, for the same reason that "const" is valuable. When values
associated with names change, it is usually harder to keep track of
what those names mean.

Of course, when immutability starts to interfere with expressive
power, it can have the opposite effect, but I have learned to prefer
immutability until it proves impractical.

Also, it's worth noting that immutable types tend to be more amenable
to efficient parallelization, so mutability is not necessarily an
efficiency win.

-- 
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