10

In an application framework when performance impact can be ignored (10-20 events per second at max),
what is more maintainable and flexible to use as a preferred medium for communication between modules - Events or Futures/Promises/Monads?

It's often being said, that Events (pub/sub, mediator) allow loose-coupling and thus - more maintainable app... My experience deny this: once you have more that 20+ events - debugging becomes hard, and so is refactoring - because it is very hard to see: who, when and why uses what.

Promises (I'm coding in Javascript) are much uglier and dumber, than Events. But: you can clearly see connections between function calls, so application logic becomes more straight-forward. What I'm afraid. though, is that Promises will bring more hard-coupling with them...

p.s: the answer does not have to be based on JS, experience from other functional languages is much welcome.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
c69
  • 1,358
  • 1
  • 12
  • 19
  • 2
    **It's often being said, that Events (pub/sub, mediator) allow loose-coupling** who the hell says that? stop listening to them! You can't subscribe to an event without knowing the parent --> tight coupling. Look into weak events (=Mediator?). – Louis Kottmann Sep 25 '12 at 08:58
  • @Baboon I generally agree that events do not automatically produce loose-coupling, but if you introduce an event bus you can subscribe to events without knowing the "parent". Who says it? Ray Ryan on Google IO 2009, see http://www.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html at 13:50. – scarfridge Sep 25 '12 at 10:12
  • @scarfridge yes, if you implement some kind of eventaggregator, it's lose coupling, as I said in my comment. – Louis Kottmann Sep 25 '12 at 11:07
  • .net rx Is an event aggregator, I'm on mobile , will post more details later – AndreasScheinert Sep 25 '12 at 14:00

1 Answers1

1

Monads and events play quite nicely together, for example have a look at .NET Rx. I think there should be even an JavaScript implementation. http://msdn.microsoft.com/en-us/data/gg577609.aspx

  • sorry for delayed accept. "some dumb thing from microsoft" is indeed awesome. And now, after Reactive Extensions have been open-sourced, they are even more viable. Thanx for the answer (though you might want to expand it a little bit ;) ). – c69 Nov 26 '12 at 21:12
  • It depends what you are looking for: some introduction or specific examples. In any case I can recommend you to explore channel9 videos and talks by Erik Meijer and Brian Beckmann on the topic. – AndreasScheinert Nov 28 '12 at 10:33