Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review
From: Gordon Woodhull (gordon_at_[hidden])
Date: 2011-03-14 22:59:14


Hi Steven,

As I mentioned in my review, I'm neither an expert in big integers nor a potential user of the library. With that disclaimer aside, let me respond.

On Mar 12, 2011, at 12:21 AM, Steven Watanabe wrote:
> On 03/09/2011 12:23 AM, Gordon Woodhull wrote:
>> The STL and its offspring are founded on the principle of separating data structures from algorithms. IMO this is important not just so that other representations of big integers could be used, but also for clarity of code.
>
> IMHO, trying to make a bigint "just like the STL"
> is simply misguided. Addition, subtraction,
> multiplication, and division aren't algorithms
> that operate on a bigint. They're the basic
> operations that define an integer.

I'm not sure how you can say they aren't algorithms; I guess you mean that the algorithms shouldn't be exposed.

I don't see anything mutually exclusive about algorithms and operators: there are algorithms that run on ranges of numeric data at one level, and there are classes that look like ints on another level.

I tend to see all such problems as data + algos at one level, and then some syntactic sugar (whether proto or just classes with operators) at another level. This allows there to be more options in the data & algos than are needed in normal usage.

From a quick glance at the code, it looks like this design is already present: all the work is actually done by free functions on "raw" integers, and then integer_t is a nice wrapper.

Whether this needs to be in the public interface is debatable, and as I argued in my review, reviews certainly shouldn't create useless work which muddies the design. I hope that everyone who expressed this opinion wasn't just jumping on a bandwagon on hearing a good-sounding slogan. I don't think so.

> Let's consider why we want to separate
> the data structures from the algorithms
> again. The basic reason is that this allows
> new data structures and new algorithms
> to be added independently. Does this apply
> here at all?

I think it boils down to a few essential questions:

Do people need to apply the +-*/ algorithms to data which is not in an integer_t data structure? It does seem that it might be easier to implement the fixed-size large integer if the algos were separate from the data, but it's not the only way.

Are there other algorithms besides these 4 which need access to the binary data?

Are there reasons to replace the +-*/ algorithms?

Cheers,
Gordon


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