From: Kevin A. <al...@se...> - 2001-12-14 19:54:26
|
Below is a slightly edited version of an email I received from Alex Martelli; I didn't change any of his comments, I just deleted the ones not relevant to the singleton and logging discussion. Also, Patrick sent me this link to an article by Alex that you may want to read. http://www.aleax.it/5ep.html As Patrick says: "More than you could ever possibly want to know about singletons and borgs in Python." ka -----Original Message----- From: Alex Martelli [mailto:al...@al...] Sent: Thursday, December 13, 2001 11:26 PM To: Kevin Altis; al...@al... Cc: ma...@he... Subject: Re: FW: singletons and logging On Friday 14 December 2001 07:12, Kevin Altis wrote: > "singleton" log and config by just using module level variables and > functions as you'll see in the list posts or cvs, but I left open the > issue of whether to use a Borg or whether my module solution is good or > not. Seems very pythonic to me, use of convention rather than > enforcement. I entirely agree that a module is a better solution than a class for many needs that people are meeting with Singleton (as well as Borg being better than Singleton for most of the rest). Remember, however, that the main Force being resolved by the Singleton DP (and the Borg non-pattern) is *inheritability*: you want client-code to be able to customize the functionality you're providing by subclassing and overriding, or at least don't want to rule it out. Singleton and Borg give you that, modules don't (client-code may customize but only by a more involved process of copying module pieces into another module and substituting others -0- often yecchy). > -----Original Message----- > From: Kevin Altis [mailto:al...@se...] > Sent: Thursday, December 13, 2001 12:22 PM > To: ma...@he... > Cc: Alex Martelli [al...@ya...] > Subject: singletons and logging > > > I started two discussions yesterday on singletons and logging, both of > which you are probably going to deal with in anygui land. The singleton > is a Python language issue and it was actually Alex's cookbook entry that > got me to post yesterday. > > http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/PythonCard > > Are you using singletons in anygui? Are you using debug or info logging Inheritance is often an interesting potential and you may well not want to rule it out. Don't know about the specific case at hand. Apart from inheritance, modules and pseudo-modules (instances installed into sys.modules) are fine. Alex |