Low dimensional matrices, vectors, quaternions and a cubic equation

Clemens eriatarka84 at gmail.com
Tue Apr 20 00:25:43 PDT 2010


Eric Poggel Wrote:

> On 4/16/2010 10:41 PM, Andrei Alexandrescu wrote:
> > Generally I'd strongly suggest making operations free generic functions
> > instead of members.
> 
> I disagree on this one.  It unnecessarily adds more names to an outer 
> namespace and makes code less readable:
> 
> vec1.cross(vec2).project(vec3).length();
> 
> vs:
> 
> length(project(cross(vec1, vec2), vec3);
> 
> The first reads naturally while the second is more like polish notation 
> and is easier to forget parentheses, as I did.

For the record: at least for cross(), I prefer the latter version. It always seemed awkward to me to make a symmetric (ok, anti-symmetric in this case) operation like this a member, because vec1.cross(vec2) doesn't look symmetric at all anymore. Furthermore, in the absence of an actual operator for the cross product (which we can't have, unless we resort to overloading abuse), the latter is closer to mathematical notation.

-- Clemens



More information about the Digitalmars-d mailing list