Movatterモバイル変換


[0]ホーム

URL:


__module__ (was Re: Deprecate self)

Alex Martellialeaxit at yahoo.com
Fri Apr 20 17:24:47 EDT 2001


"Rainer Deyke" <root at rainerdeyke.com> wrote in messagenews:a8_D6.60935$J%5.20446933 at news2.rdc2.tx.home.com...    [snip]> Just as I can use the term "command" to refer something different from the> Command design pattern (note different capitalization), I generally usethe> word singleton to refer to something that is not necessarily implemented> through the Singleton design pattern.Makes sense, which is why I asked very specifically, when youmentioned singletons, whether you had examples where youfound the Singleton design pattern best.  Apparently youranswer was not to the question I asked.> > That there exist design situations where a single copy of a> > certain "state" is desirable, is hardly in question -- that IS> > a force that comes up again and again.  The issue is how to> > best resolve it, and the other forces that accompany it in> > various use cases.>> What generic word would you use to refer to an object that encapsulates> program-wide unique state?As it happens, in my favourite (free-time) application area, I hadbetter avoid naming such object 'singletons' any more than I couldname others 'doubles', 'diamonds' or 'squeezes' -- these are allimportant words and concepts in contract bridge (and, some ofthem, in other games, too -- but bridge is my field).Apart from application areas -- in maths, a singleton is a set witha single member... it's not that member (and the distinction isimportant).  If one looks at a _class_ as somehow equivalent tothe set of its instances, then calling the *class* 'a singleton' maymake sense, but calling the *instance* 'a singleton' would not.> > > Python is more than complex enough for me.> >> > So how would __module__ and __istance__ and __function__> > and all other such additions REDUCE its complexity that> > you perceive?>> See above for my Grand Unification Scheme.  '__module__', at least, makes> 'global' redundant.  As I stated in another thread, sometimes you need to> add new features before you can remove old ones.  '__module__' seemssimpler> to me than the one-and-only non-executable statement in Python.If modifying globals from inside a function is meant to be a rarething, then I agree with you that using "__module__.x=y" &c forsuch modifications (rather than "global x" followed by "x=y") maybe perfectly acceptable.  The global statement does cater betterfor a style in which such "rebinding of globals" from within afunction come "in clusters" -- many functions may not need todo any such binding, but those that do may need to bind morethan one global or at least bind a global in several places, e.g.def example():    global x,y,z    if x>0:        x=y=z=23    elif y<z:        x=y=z=34is already substantially more readable than an equivalentusing __module__ six times.'global' does (in my modest experience) give some problemto some students, typically coming out as expressions ofastonisment that some equivalent ofx=23def f():    print x    x=45    print xfails.  This empirical observation does lend some support toyour thesis.  However, I wonder if having the 'fix' be changingthe assignment to "__module__.x=45", rather than insertinga "global x", would do all that much good in this regard.Alex


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp