Clemens wrote:
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
Oddly I tend to like v1.cross(v2) because for me that feels closer to
the the mathematical notation with the cross sitting between the two
vectors. But for D at least it's a none issue because both will work.