3 ms·
Reactive Cocoa, and functional reactive programming in general, is difficult to get your head around. I've tried several times to see why it's worth it, and eac
by danpalmer 13y ago
Reactive Cocoa, and functional reactive programming in general, is difficult to get your head around. I've tried several times to see why it's worth it, and each time come a little closer. After 3 attempts, I finally do think it is beneficial, but it's not immediately obvious. Here are a few reasons:
1. It enables you to eliminate state. My view controllers always end up with various handles to objects on them so that I can access things during a complicated processing sequence. These things cause edge case bugs, and are generally not a nice thing to have lying around in code.
2. The more I write data processing algorithms, the more I think about them in terms of map, reduce, filter and other similar operations. Reactive Cocoa allows those to be used to control the flow of execution even more, and it fits really nicely with how I'm thinking about algorithms.
3. I've tried some development in QML for Ubuntu Touch, a language which is very declarative, and it was wonderful. It's a very different way of working, but I can really imagine that being the norm in 20 years. Reactive Cocoa, allowing for more declarative coding, brings a small element of that to Objective-C, which is nice.
4. Finally, I found it fits really nicely with the MVVM (Model, View, View-Model) architecture, which in turn feels like a nice and clean way of structuring applications, and appears to be really easy to test. I haven't got too far into testing Reactive Cocoa applications yet, but it looks like they should be very easy to test as the boundaries between each component are much better defined, and inherently more testable.
I highly recommend "Functional Reactive Programming on iOS" by Ash Furrow: https://leanpub.com/iosfrp https://leanpub.com/iosfrp – I'm nearly at the end of it, and it's helped me understand more about Reactive Cocoa and make it seem a bit less 'magic', which was a feeling I got from the readme on the project's GitHub repo.
Also for some of the reasoning behind FRP, the paper "Out of the Tar Pit" is a good read: http://shaffner.us/cs/papers/tarpit.pdf http://shaffner.us/cs/papers/tarpit.pdf.