On Jan 13, 12:28 am, Jeff Schwab <(E-Mail Removed)> wrote:

> Mirco Wahab wrote:

> > after working with some more algebra and a

> > homebrewn overloaded (lightweight) vector/matrix

> > class, I'm somehow weary of writing V.length() all

> > the time

> > After looking through available operators,

> > the only feasible operator would be the '~',

> > for the vector length, therefore having code

> > like this:

> > ...

> > double cos_a = ( (C-A) * (B-A) ) // V * W => some dot product

> > / ( ~(C-A) * ~(B-A) ); // ~V => vector scalar length

> > ...

> > which looks "almost" idiomatic.

> > Any other ideas? Are there potential

> > precedence traps to be expected?

> You could instead define a stand-alone length function that

> calls the length method. That would save you the . operator,

> and leverage the existing parentheses in your sample code.

> > Or should I better stick with

> > ...

> > / ( (C-A).length() * (B-A).length() )

> > ...

>

> / ( length(C-A) * length(B-A) )
That's an interesting idea. I don't buy the "saving the .

operator" part, but the notation does seem to conform more to

typical mathematic notation. I'd argue for the use of . is

preferred with objects have some associated "behavior", but I

don't think that that's really the case here. And other

functions, which you add later (or which someone who doesn't

have access to the matrix code adds) will also use this syntax.

> It is common in the STL to call these functions "size," rather

> than "length:"

> / ( size(C-A) * size(B-A) )
It's also common in many places for size to indicate the number

of bytes (as in the sizeof operator) and length the number of

elements.

In this case, however, I think he's concerned with a

mathematical concept. In which case, he should use whatever is

most frequent in mathematics. (If he wants to be really clear:

elementCount for the number of elements, magnitude for the

corresponding mathematical concept. Of course, if he's already

complaining about the length of length...)

--

James Kanze (GABI Software) email:(E-Mail Removed)

Conseils en informatique orientée objet/

Beratung in objektorientierter Datenverarbeitung

9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34