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


Groups > comp.lang.python > #43301

Functional vs. Object oriented API

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mpwb500@york.ac.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'python,': 0.02; 'api.': 0.05; 'class,': 0.07; 'great.': 0.07; 'linear': 0.09; 'algebra,': 0.16; 'subject:API': 0.16; 'subject:Object': 0.16; 'subject:oriented': 0.16; 'java,': 0.16; 'have:': 0.19; '>>>': 0.22; 'preferred': 0.22; 'python?': 0.22; "i've": 0.25; 'function': 0.29; 'direction': 0.30; "i'm": 0.30; 'getting': 0.31; 'class': 0.32; 'actual': 0.34; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'choosing': 0.36; 'largely': 0.36; 'method': 0.36; 'charset :us-ascii': 0.36; 'thanks': 0.36; 'hi,': 0.36; 'example,': 0.37; 'unit': 0.37; 'too': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'matter': 0.61; 'header:Message-Id:1': 0.63; 'personal': 0.63; 'such': 0.63; 'studies': 0.65; 'subject:. ': 0.67; 'between': 0.67; 'max.': 0.84; 'reading,': 0.84; 'received:86': 0.91
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:content-type:content-transfer-encoding:subject :message-id:date:to:mime-version:x-mailer:x-gm-message-state; bh=oxvH8eWWassl1nwd6f5bYWYlfNdasQSSVRpWGu5sSt4=; b=EDWj/dGi1jAHb0njLSjsZlVpIRVPBOo7DaG2fSCdgYYvqCYJ1SzVRi5AB+BatgIjbG f5dSEIrKrXXkYnw/7BA3WkpRDXFzfhWLbcL4ud5nLUbzbmO3yxqX2PhiQgLOKaF2p/Yv mrWW11UAje6rchD/7uTo7r79ovo4kQkJZHYh6azDa3I4vwpEt3vmFthiNk/TyWNGkiGQ DkpCIRsUp/xtlnOm53gHMxG7ImrgTLKe/Tx4mL0ilXR7tqfWACJLAE+Vci0qYEPygR3w acpK/J63j08Qch3ZnTQ8ummMI8p/0cdarbBqFB//A5veD7KZAXmSbd7CJ1M+B4SmVB2N lAbw==
X-Received by 10.180.39.207 with SMTP id r15mr6498683wik.16.1365635782395; Wed, 10 Apr 2013 16:16:22 -0700 (PDT)
From Max Bucknell <mpwb500@york.ac.uk>
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding quoted-printable
Subject Functional vs. Object oriented API
Date Thu, 11 Apr 2013 00:16:19 +0100
To python-list@python.org
Mime-Version 1.0 (Mac OS X Mail 6.3 \(1503\))
X-Mailer Apple Mail (2.1503)
X-Gm-Message-State ALoCoQlcq2oBMWVPGbYnqS0IJ0iwgaPpcESmX/HHOU9eKJuvlVBxB7wej/goe5LbJU8hExdbF5cW
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.429.1365635789.3114.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365635789 news.xs4all.nl 2575 [2001:888:2000:d::a6]:56665
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43301

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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