Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-10-12 18:19:08


"Deane Yang" wrote
> Andy Little wrote:
>> "Matt Calabrese" wrote
>>
>>> I'm not going to make bad code easy to write by allowing points to be added
>>> with operator +.
>>
>> You seem to be making good code more difficult to write though. :-(
>
> I humbly disagree. He's trying to differentiate between interface and
> implementation, to make it easier to write good code.

You need + in the interface so users like me can write out the formulas as they
see them written down.

[cut]

>> hmm.... Geometry does define addition of points....
>
> Not that I'm aware of. Could you elaborate? Given two points, A and B,
> "A+B" makes no geometric sense but "tA + (1-t)B" does. You should think
> of the latter as a primitive geometric operation.

err... hmm ... "tA + (1-t)B" is using '+' , Isnt it?

>The fact that it can
> be written in terms of vector addition is an implementation detail and
> should be hidden from the interface.

Nonsense. '+' should be part of the interface.

[cut]

>> Addition is pretty common e.g for curves, for piecewise integrals(e.g
>> Simpsons
>> rule) etc. Physical data is noisy more often then not.
>
> If you parse these formulas carefully, you will see that they can always
> be written in terms of the following operations only:
>
> point +/- vector = point
> vector +/- vector = vector
> vector */ scalar = vector

If the goal is to write good code, then please dont cooerce me to do home-made
rearrangements of standard formulas to hide +. Thats a source of errors if ever
there was one ;-)

>> You havent actually removed addition. You've just given it a
>> non-obvious name. ;-)
>
> No. He's removed addition of points from the interface and hidden it in
> the implementation.

No.. hes just changed the name . Its still in the interface., unless he's
planning not to make the component_add function available to users. FWIW a
reinterpret_cast to a vector looks like the easiest workaround!

> I agree with this. This for me makes it easier to
> write good code, not harder, because it protects you from coding
> incorrect formulas involving points.

It certainly wastes my time trying to find workarounds or rearranging perfectly
good formulae.to use '-'. More work for anyone reading or reviewing the code
too.

[cut]

>> I dont see how changing the name of the function helps. componentwise_add is
>> an
>> addition right?
>
> By using a long and conspicuous name, it signals to the programmer that
> the formula should be checked with extra care, since the compiler cannot
> verify that only allowable operations are used in the formula.

Maybe it makes the programmer wonder why they didnt provide operator +.

This type of code is usually written using floating point types. I would suggest
making the library as simple to use as possible.

regards
Andy Little

 


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