5 ms·
Aren't Django signals a little like COMEFROM?
- Zak 17y agoIt's better because it doesn't require messing around with, or even being aware of the internals of the code it's being connected to. It's actually a lot like a Common Lisp :before method, which I've found really bloody useful on a few occasions.
- ubernostrum 17y agoI've always just looked at them the way I look at any other event-based hooks -- they're a way to say "when this thing happens, I want to know about it and run some code". Some programming languages even have this built in :)
- shabda 17y agoBut doesn't it lead itself to "Action at distance" anti pattern? Like everyone else, we use django-regsitration a lot. Here in your code, http://bitbucket.org/ubernostrum/django-registration/src/tip/registration/models.py http://bitbucket.org/ubernostrum/django-registration/src/tip... you send a custom signal. Now any one can break the normal flow of control and call control _from any where in the project to anywhere in the project_.
- thedz 17y agoSignals defines a fairly concise interface for interacting with events. You're not "stealing" control from the loop. Rather, think of it more as listening and attaching something to an event. For me, it helps to think of signals less as interrupts in a traditional program loop, but as something more akin to events in event-driven environments.
- DougBTX 17y agobreak the normal flow of control But after the signal is fired, and handlers do their handling, normal flow is restored and the code just after the signal resumes (assuming no exceptions were thrown). COMEFROM doesn't make that guarantee, making it much harder to follow. It isn't that code can jump to an arbitrary point in the program (a function call can do that) but that the code after that point won't get called, barring a corresponding GOTO back to the label.
- pistoriusp 17y agoI think it's fine to say that you don't like signals. But I wouldn't do so without proposing a better alternative.
- Confusion 17y agoNo they aren't. They are an implementation of the template method pattern, perhaps with some cross polination from an observer pattern.