Plurk

26 responses to this plurk (Jump to bottom)

  • shaf
    (applause) nice to see ppl giving back to the community.. ps __trash_singleton ?? (!!)
  • shaf
    Have you worked than one out yet ?
  • muhuk says
    shaf: that's very very old code. It was one of my first projects for learning python.
  • muhuk says
    But it still works on my box :-)) New version is cooking, soon to be committed.
  • shaf
    asks if it's that simple to implement the singleton pattern in python
  • timka.org says
    shaf: I use __new__ which always returns the single instance stored in a class attribute
  • shaf
    yeah but what's to stop you from executing the script using another python intepreter ? Singleton breaks.
  • shaf
    It's just that singleton is the simplest pattern to understand but can be tricky to implement if you don't understand your compiler/interptr
  • timka.org says
    shaf: Another interpreter runs another instance of your program which has its own singleton instance.
  • shaf
    exactly
  • timka.org says
    shaf: I mean Singleton is usually limited to one process no matter what language you use, so multiple *program* instances is out of scope.
  • shaf
    timka_org yep. I know all this already. But as any good programmer would know, singleton in practice is not guarenteed
  • shaf
    this is why in any good production environment. Singleton is frowned upon
  • timka.org says
    Yeah, in our production environment at work two instances of our app can fuck up the DB just because nobody cared about proper locking :-&
  • timka.org says
    It's about thread-safety inside single process, but you were talking about multiple processes
  • shaf
    hence the reason for me to have mixed feelings about it. If used - use it carefully
  • shaf
    well some idiot programmers assume singletons to work across processes too (doh)
  • timka.org says
    Agree. And punish those who break the conventions! :-))
  • timka.org says
    I think you can only fire or train them. Hard choice...
  • muhuk says
    on the other hand, most of the time singleton is not really needed in practice. Surely there is one trash (per user) but I have come to...
  • muhuk says
    ...realize I don't need a singleton trash wrapper class at all. It is even making things harder to unittest.
  • muhuk says
    Btw, a singleton shouldn't be confused as a concurrency mechanism (especially in multi-process systems).
  • timka.org says
    Anyway, Singleton is just an object creation pattern, conceptually it has nothing to do with concurrency.
  • timka.org says
    However, correct implementations must be aware of the used concurrency model

Ads