What's the right way for doing this in D?
Namespace
rswhite4 at googlemail.com
Sat Aug 24 02:40:56 PDT 2013
I liked to know which of this two methods is more common to you,
A or B:
Method A:
----
import std.stdio;
struct Vector2f {
public:
float x;
float y;
float dot(ref const Vector2f vec) const {
return this.x * vec.x + this.y * vec.y;
}
}
----
Method B:
----
struct Vector2f {
public:
float x;
float y;
}
float dot(ref const Vector2f lhs, ref const Vector2f rhs) {
return lhs.x * rhs.x + lhs.y * rhs.y;
}
----
Until now I used Method A, but because of UFCS and the fact, that
the dot product doesn't affect the object, I thought about which
way would make more sense. I still like Method A but I'm curious
what you think.
More information about the Digitalmars-d-learn
mailing list