Functional vs. Object oriented API

Xavier Ho contact at xavierho.com
Wed Apr 10 19:27:08 EDT 2013


Hi Max,

In Python, we prefer readability over anything else.  The simpler you can
write it, the better it can be understood.

That said, I've never considered using (i, j, k) as a vector component
before.  I've always done something akin to:

>>> vector = Vector(2, 4, 6)
>>> print (vector.normalize().y)

However, if you use the mathematical definition of a vector, with standard
symbols:

    v = x*i + y*j + z*k

Then I believe vector.j is a much choice.  As long as your documentation
states it's read-only, I think most mathematicians will love that notation.

.

As far as dot products go, there isn't really a big difference between the
two forms you have there.  Both are equally as readable.

When C++ was invented people had already debated about the two forms.
 There isn't a general consensus on this debate, but most would probably
agree that overloading the * operator of a vector to do dot product is a
bad idea, since some people want cross product, or per-component
multiplication.  At the end of the day, dot() or dot_product() is more
readable, and it doesn't matter if you have it as a function in or outside
of a vector's class.

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130411/9c7b0725/attachment.html>


More information about the Python-list mailing list