Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43301
| From | Max Bucknell <mpwb500@york.ac.uk> |
|---|---|
| Subject | Functional vs. Object oriented API |
| Date | 2013-04-11 00:16 +0100 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.429.1365635789.3114.python-list@python.org> (permalink) |
Hi,
I'm currently learning Python, and it's going great. I've dabbled before, but really getting into it is good fun.
To test myself, and not detract too much from my actual studies (mathematics), I've been writing my own package to do linear algebra, and I am unsure about how best to structure my API.
For example, I have a vector class, that works like so:
>>> a = Vector([2, 7, 4])
>>> b = Vector.j # unit vector in 3D y direction
I also have a function to generate the dot product of these two vectors. In Java, such a function would be put as a method on the class and I would do something like:
>>> a.dot_product(b)
7
and that would be the end of it. But in Python, I can also have:
>>> dot_product(a, b)
7
Which of these two are preferred in Python? And are there any general guidelines for choosing between the two styles, or is it largely a matter of personal preference?
Thanks for reading,
Max.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Functional vs. Object oriented API Max Bucknell <mpwb500@york.ac.uk> - 2013-04-11 00:16 +0100
Re: Functional vs. Object oriented API Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-12 04:20 +0000
Re: Functional vs. Object oriented API Roy Smith <roy@panix.com> - 2013-04-12 10:19 -0400
Re: Functional vs. Object oriented API Mitya Sirenef <msirenef@lightbird.net> - 2013-04-12 10:29 -0400
Re: Functional vs. Object oriented API David M Chess <chess@us.ibm.com> - 2013-04-12 11:37 -0400
Re: Functional vs. Object oriented API 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-12 22:25 -0700
Re: Functional vs. Object oriented API 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-12 22:25 -0700
Re: Functional vs. Object oriented API Rui Maciel <rui.maciel@gmail.com> - 2013-04-13 09:51 +0100
csiph-web