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


Groups > comp.lang.python > #70551

Re: Moving to an OOP model from an classically imperitive one

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'read.': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'classes,': 0.05; 'irc': 0.05; 'class,': 0.07; 'string': 0.09; 'advice.': 0.09; 'classes.': 0.09; 'currently,': 0.09; 'lawrence': 0.09; 'messing': 0.09; 'oop': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:github': 0.09; 'def': 0.12; 'language.': 0.14; 'attributes:': 0.16; 'dictionary.': 0.16; 'identifier.': 0.16; 'obviously,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:OOP': 0.16; 'tuple': 0.16; 'java,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'file,': 0.19; 'written': 0.21; 'seems': 0.21; 'import': 0.22; 'separate': 0.22; 'header :User-Agent:1': 0.23; 'logical': 0.24; 'manager.': 0.24; 'replace': 0.24; 'file.': 0.24; '---': 0.24; "i've": 0.25; 'source': 0.25; 'define': 0.26; 'pass': 0.26; 'certain': 0.27; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'tim': 0.29; 'moved': 0.30; 'asked': 0.31; 'program,': 0.31; 'code': 0.31; 'about.': 0.31; 'though.': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'skip:# 10': 0.33; 'subject:from': 0.34; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'subject:one': 0.36; 'method': 0.36; 'possible': 0.36; 'example,': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'files': 0.38; 'does': 0.39; 'moving': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'free': 0.61; 'new': 0.61; 'viruses': 0.61; 'simple': 0.61; "you're": 0.61; 'email addr:gmail.com': 0.63; 'protection': 0.63; 'such': 0.63; 'our': 0.64; 'between': 0.67; 'antivirus': 0.68; 'received:2': 0.84; 'single,': 0.84; 'subject:Moving': 0.84; 'url:master': 0.84; 'suffer': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Moving to an OOP model from an classically imperitive one
Date Wed, 23 Apr 2014 22:15:03 +0100
References <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-2-98-192-136.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
In-Reply-To <80a82415-fc67-4ccf-8827-27a0ba5459b7@googlegroups.com>
X-Antivirus avast! (VPS 140423-0, 23/04/2014), Outbound message
X-Antivirus-Status Clean
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9469.1398287725.18130.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1398287725 news.xs4all.nl 2924 [2001:888:2000:d::a6]:38545
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70551

Show key headers only | View raw


On 23/04/2014 21:57, tim.thelion@gmail.com wrote:
> Hello,
>
> I am currently writting a program called subuser(subuser.org), which is written as classically imperative code.  Subuser is, essentially, a package manager.  It installs and updates programs from repositories.
>
> I have a set of source files https://github.com/subuser-security/subuser/tree/master/logic/subuserCommands/subuserlib which have functions in them.  Each function does something to a program, it identifies the program by the programs name.  For example, I have an installProgram function defined as such:
>
> def installProgram(programName, useCache):
>
> Now I've run into a flaw in this model.  There are certain situations where a "programName" is not a unique identifier. It is possible for two repositories to each have a program with the same name.  Obviously, I could go through my code and replace all use of the string "programName" with a tuple of (programName, repository).  Or I could define a new class with two attributes: programName and repository, and pass such a simple object arround, or pass a dictionary.  However, I think this would be better solved by moving fully to an OOP model.  That is, I would have a SubuserProgram class which had methods such as "install", "describe", "isInstalled"...
>
> There is one problem though.  Currently, I have these functions logically organized into source files, each between 40 and 170 LOC.  I fear that if I were to put all of these functions into one class, than I would have a single, very large source file.  I don't like working with large source files for practicall reasons.  If I am to define the class SubuserProgram in the file SubuserProgram.py, I do not want all <https://github.com/subuser-security/subuser/blob/master/logic/subuserCommands/subuserlib/run.py#L162> of run.py to be moved into that file as well.
>
> I thought about keeping each method in a separate file, much as I do now, something like:
>
> ###################
> #FileA.py
> ###################
> def a(self):
>    blah
>
> ###################
> #FileB.py
> ###################
> def b(self):
>    blah
>
> ###################
> #Class.py
> ###################
> import FileA, FileB
> class C:
>    a=FileA.a
>    b=FileB.b
>
> This works, but I find that it is hard to read.  When I come across FileA, and I see "self" it just seems very confusing.  I suffer a bout of "who-am-i"ism.
>
> I asked on IRC and it was sugested that I use multiple classes, however I see no logical way to separate a SubuserProgram object into multiple classes.
>
> So I thought I would seek your advice.
>
> Tim
>

You're writing Python, not Java, so put your code into one file and stop 
messing about.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

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


Thread

Moving to an OOP model from an classically imperitive one tim.thelion@gmail.com - 2014-04-23 13:57 -0700
  Re: Moving to an OOP model from an classically imperitive one Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-23 22:15 +0100
  Re: Moving to an OOP model from an classically imperitive one Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-23 15:23 -0600
    Re: Moving to an OOP model from an classically imperitive one Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-24 12:26 +1200
  Re: Moving to an OOP model from an classically imperitive one Ethan Furman <ethan@stoneleaf.us> - 2014-04-23 14:42 -0700
    Re: Moving to an OOP model from an classically imperitive one tim.thelion@gmail.com - 2014-04-24 00:32 -0700
  Re: Moving to an OOP model from an classically imperitive one MRAB <python@mrabarnett.plus.com> - 2014-04-24 00:08 +0100
    Re: Moving to an OOP model from an classically imperitive one tim.thelion@gmail.com - 2014-04-24 00:21 -0700
      Re: Moving to an OOP model from an classically imperitive one Chris Angelico <rosuav@gmail.com> - 2014-04-24 17:36 +1000
      Re: Moving to an OOP model from an classically imperitive one Steven D'Aprano <steve@pearwood.info> - 2014-04-24 09:08 +0000
  Re: Moving to an OOP model from an classically imperitive one Chris Angelico <rosuav@gmail.com> - 2014-04-24 09:12 +1000
  Re: Moving to an OOP model from an classically imperitive one Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-24 12:21 +1200
    Re: Moving to an OOP model from an classically imperitive one tim.thelion@gmail.com - 2014-04-24 09:53 -0700
      Re: Moving to an OOP model from an classically imperitive one Amirouche Boubekki <amirouche.boubekki@gmail.com> - 2014-04-25 19:21 +0200
  Re:Moving to an OOP model from an classically imperitive one Dave Angel <davea@davea.name> - 2014-04-23 22:01 -0400

csiph-web