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


Groups > comp.lang.python > #32597

Re: Organisation of python classes and their methods

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <martinhewitson@mac.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'algorithms,': 0.07; 'class,': 0.07; 'nicely': 0.07; 'ok.': 0.07; 'python': 0.09; 'methods,': 0.09; 'subject:python': 0.11; 'file,': 0.15; 'grouped': 0.16; 'languages)': 0.16; 'reasonable.': 0.16; 'received:mac.com': 0.16; 'subject:their': 0.16; 'martin': 0.16; 'wrote:': 0.17; '(in': 0.18; 'code.': 0.20; 'to:name:python- list@python.org': 0.20; 'lets': 0.22; 'cc:2**0': 0.23; 'class.': 0.23; "i've": 0.23; 'seems': 0.23; '(this': 0.24; 'paul': 0.24; 'so.': 0.24; 'tried': 0.25; 'am,': 0.27; 'lines': 0.28; 'this?': 0.28; 'actual': 0.28; 'run': 0.28; 'writes:': 0.29; 'starts': 0.29; 'source': 0.29; 'class': 0.29; 'this.': 0.29; 'classes': 0.30; 'ease': 0.30; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'getting': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'thanks': 0.34; 'data,': 0.35; 'path': 0.35; 'received:17': 0.35; 'so,': 0.35; 'doing': 0.35; 'received:192.168.0': 0.35; 'sometimes': 0.35; 'there': 0.35; 'but': 0.36; 'alone': 0.36; 'data.': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'called': 0.39; 'short': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'kind': 0.61; 'different': 0.63; 'more': 0.63; 'natural': 0.65; '3000': 0.71; 'sounds': 0.71; 'ime': 0.84; 'numbers:': 0.91; 'thoughts,': 0.91; 'hundred': 0.95
MIME-version 1.0
Content-transfer-encoding 7BIT
Content-type text/plain; CHARSET=US-ASCII
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:5.7.7855,1.0.431,0.0.0000 definitions=2012-11-02_01:2012-11-01, 2012-11-02, 1970-01-01 signatures=0
X-Proofpoint-Spam-Details rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1211020016
Subject Re: Organisation of python classes and their methods
From Martin Hewitson <martinhewitson@mac.com>
In-reply-to <7xa9v0wj2g.fsf@ruckus.brouhaha.com>
Date Fri, 02 Nov 2012 09:08:07 +0100
References <mailman.3177.1351840590.27098.python-list@python.org> <7xa9v0wj2g.fsf@ruckus.brouhaha.com>
To "python-list@python.org" <python-list@python.org>
X-Mailer Apple Mail (2.1499)
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.3180.1351843706.27098.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351843707 news.xs4all.nl 6967 [2001:888:2000:d::a6]:49445
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32597

Show key headers only | View raw


On 2, Nov, 2012, at 08:38 AM, Paul Rubin <no.email@nospam.invalid> wrote:

> Martin Hewitson <martinhewitson@mac.com> writes:
>> So, is there a way to put these methods in their own files and have
>> them 'included' in the class somehow? ... Is there an official python
>> way to do this? I don't like having source files with 100's of lines
>> of code in, let alone 1000's.
> 
> That code sounds kind of smelly... why are there so many methods per
> class?  

Simply because there are many different ways to process the data. The class encapsulates the data, and the user can process the data in many ways. Of course, one could have classes which encapsulate the algorithms, as well as the data, but it also seems natural to me to have algorithms as methods which are part of the data class, so the user operates on the data using methods of that class. 

> 
> Python lets you inject new methods into existing classes (this is
> sometimes called duck punching) but I don't recommend doing this.

Is there not a way just to declare the method in the class and put the actual implementation in another file on the python path so that it's picked up a run time?

> 
> A few hundred lines of code in a file is completely reasonable.  Even a
> few thousand is ok.  IME it starts getting unwieldy at 3000 or so.

In all other projects (in other languages) I've always tried to keep individual files short to ease maintainability and search-ability (if there is such a word).

Even if one takes reasonable numbers: 20 methods, each method has 20 lines of documentation, then we immediately have 400 lines in the file before writing a line of code. It would seem much more natural to me to have these methods in their own file, grouped nicely in sub-directories. But it seems this is not the python way. Sigh.


Thanks for your thoughts,

Martin

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


Thread

Organisation of python classes and their methods Martin Hewitson <martinhewitson@mac.com> - 2012-11-02 07:16 +0100
  Re: Organisation of python classes and their methods Paul Rubin <no.email@nospam.invalid> - 2012-11-02 00:38 -0700
    Re: Organisation of python classes and their methods Martin Hewitson <martinhewitson@mac.com> - 2012-11-02 09:08 +0100
      Re: Organisation of python classes and their methods Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-11-02 11:18 +0100
        Re: Organisation of python classes and their methods Martin Hewitson <martinhewitson@me.com> - 2012-11-02 15:49 +0100
        Re: Organisation of python classes and their methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-02 17:02 +0000
      Re: Organisation of python classes and their methods Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-03 01:38 +0000
    Re: Organisation of python classes and their methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-02 08:40 +0000
      Re: Organisation of python classes and their methods Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-02 10:20 +0000
    Re: Organisation of python classes and their methods Chris Angelico <rosuav@gmail.com> - 2012-11-02 20:15 +1100
    Re: Organisation of python classes and their methods Martin Hewitson <martinhewitson@mac.com> - 2012-11-02 09:45 +0100
    Re: Organisation of python classes and their methods Peter Otten <__peter__@web.de> - 2012-11-02 11:21 +0100
    Re: Organisation of python classes and their methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-02 10:48 +0000
    Re: Organisation of python classes and their methods Robert Kern <robert.kern@gmail.com> - 2012-11-02 10:55 +0000
    Re: Organisation of python classes and their methods Robert Kern <robert.kern@gmail.com> - 2012-11-02 11:07 +0000
  Re: Organisation of python classes and their methods Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-03 01:06 +0000
    Re: Organisation of python classes and their methods Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-03 01:08 +0000

csiph-web