Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43303

Re: Functional vs. Object oriented API

References <CA923438-A718-46D4-9901-5043EACD7A22@york.ac.uk>
From Xavier Ho <contact@xavierho.com>
Date 2013-04-11 09:27 +1000
Subject Re: Functional vs. Object oriented API
Newsgroups comp.lang.python
Message-ID <mailman.431.1365636451.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Functional vs. Object oriented API Xavier Ho <contact@xavierho.com> - 2013-04-11 09:27 +1000

csiph-web