This proposal by <a href="/users/aanand">Aanand Prasad</a> has been chosen by the community to be given at Ruby Manor 4.
updated over 4 years ago; latest suggestion over 4 years ago
Functional programming: the idea that won’t go away. We’ve been discussing it in the Ruby world ever since we learned how to
inject, and we still have barely any idea what we’re doing. If only we could just forget about it.
We can’t. It’s here again, and this time it wants our callbacks. In Functional Reactive Programming, instead of modelling state as mutable variables, we build programs out of (potentially infinite) streams of events and values, composing, mapping, filtering and reducing our way to solid, easy-to-reason-about code. At least, that’s the idea.
Does it work in practice? Does it make sense to model the world this way? What do we gain? What do we lose? Are we obscuring the intent of the code, or are we just too wrapped up in the imperative paradigm to recognise there are other ways of seeing? And—what on earth, is that a stream of functions?
The Ruby connection is admittedly tenuous here, as FRP is most relevant in the context of GUI programming (where input and output are constant and interleaved). I have a few ideas for example apps with which to demonstrate principles:
- EventMachine-based server of some kind
- RubyMotion app
- Simple game (e.g. Pong)
Hell yes. This sounds great! If you wanted to move away from GUI development as a motivating example, might I suggest that online algorithms (for eg analytics or data processing) might be an interesting area to apply FRP to? This isn't a specific request mind, just a suggestion if you're stuck for non-GUI ideas. I'd be very excited to hear about doing FRP with Ruby in general.
Btw, also, have you seen Rubactive? it's an existing FRP implementation in Ruby.
Good call—I was just thinking that. Added to the list.
Yes please. Could you do something convincing in a traditionally async Ruby setting, e.g. with EventMachine? WebSockets? All that jazz?