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


Groups > comp.lang.python > #86640

Re: suggestions for functional style (singleton pattern?)

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'example:': 0.03; 'debugging': 0.07; 'already.': 0.09; 'attributes': 0.09; 'scripts,': 0.09; 'url:github': 0.09; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'repl': 0.16; 'singleton': 0.16; 'subject:?)': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; 'code,': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'especially': 0.30; 'code': 0.31; 'though.': 0.31; 'class': 0.32; 'interface': 0.32; 'skip:d 20': 0.34; 'subject: (': 0.35; 'good.': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'should': 0.36; 'example,': 0.37; 'implement': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'functional': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'address': 0.63; 'kind': 0.63; 'places': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'potentially': 0.81; 'clearer': 0.84; 'url:master': 0.84; 'difficult,': 0.91; 'state.': 0.95
X-Virus-Scanned amavisd-new at torriefamily.org
Date Sat, 28 Feb 2015 19:19:32 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: suggestions for functional style (singleton pattern?)
References <WXrIw.14066$uP4.9692@fx20.iad>
In-Reply-To <WXrIw.14066$uP4.9692@fx20.iad>
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
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.0.1425176390.29956.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1425176390 news.xs4all.nl 2905 [2001:888:2000:d::a6]:48463
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86640

Show key headers only | View raw


On 02/28/2015 04:12 PM, yves@zioup.com wrote:
> For some scripts, I write in a a more functional way, using a lot of small
> functions outside of any class. Although it makes the code clearer for
> specific cases, I have found that it makes debugging and using the repl in
> general difficult, as as I have to re-initialise every single objects every time.
> 
> I have now started to use some kind of state pattern to alleviate this, here's
> a simplistic example:
> 
> https://github.com/dorfsmay/state_pattern_for_debugging_python/blob/master/dirstats.py
> 
> Are there better ways to address this? Any suggestion on this style?

You say you are trying to use a singleton pattern, but your code does
not appear to implement a singleton.  From what I can read of your code,
you really should just put all your functions as methods to the DirStat
class and call it good.  Especially if your module is going to be used
in several places potentially at the same time.

If what you want is a singleton, then that's what a module is already.
Module functions are singleton methods and module attributes maintain
state.  Just call your module dirstat and interface with it:

dirstat.opendir(**vars(args)
dirstat.print()

In this example, I really don't think the singleton is a good pattern,
though.

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


Thread

suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 16:12 -0700
  Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 19:19 -0700
    Re: suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 21:11 -0700
      Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 22:14 -0700
  Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-01 04:45 +0100
    Re: suggestions for functional style (singleton pattern?) yves@zioup.com - 2015-02-28 21:29 -0700
      Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-02-28 22:05 -0700
        Re: suggestions for functional style (singleton pattern?) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 02:55 +1100
        Re: suggestions for functional style (singleton pattern?) Fabien <fabien.maussion@gmail.com> - 2015-03-02 11:19 +0100
          Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-02 11:31 +0100
          Re: suggestions for functional style (singleton pattern?) Michael Torrie <torriem@gmail.com> - 2015-03-02 08:59 -0700
          Re: suggestions for functional style (singleton pattern?) Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-02 09:51 -0700
      Re: suggestions for functional style (singleton pattern?) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-01 19:00 +1300
    Re: suggestions for functional style (singleton pattern?) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 02:04 +1100
      Re: suggestions for functional style (singleton pattern?) Mario Figueiredo <marfig@gmail.com> - 2015-03-01 19:20 +0100
  Re: suggestions for functional style (singleton pattern?) Paul Rubin <no.email@nospam.invalid> - 2015-02-28 22:23 -0800

csiph-web