Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86640
| Date | 2015-02-28 19:19 -0700 |
|---|---|
| From | Michael Torrie <torriem@gmail.com> |
| Subject | Re: suggestions for functional style (singleton pattern?) |
| References | <WXrIw.14066$uP4.9692@fx20.iad> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.0.1425176390.29956.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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