6 ms·
Aside from hijacking the term reactive-programming[1] (though it does give it a mention) this text repeats another mistake the Reactive Manifesto makes, namely
by pron 12y ago
Aside from hijacking the term reactive-programming[1] (though it does give it a mention) this text repeats another mistake the Reactive Manifesto makes, namely confuse intent (or abstraction) with implementation.
Even using the (quite unclear) hijacked definition of "reactive", there is absolutely nothing tying the goal of responsive programs to concepts such as asynchronous APIs, promises and observables. As an example, Erlang (and later Go) has been used to write "reactive" software with neither a hint nor a mention of callbacks, promises or observables (at least for the purposes outlined in this text).
Those concepts are mere implementation tricks designed to circumvent blocking in environments that either don't have support for multi-threading at all (which makes blocking impossible if concurrency is to be maintained), or those where threads are necessarily kernel threads (where blocking entails a significant overhead). In fact, the whole notion of non-blocking is entirely accidental to the discussion of responsive/concurrent applications. Where lightweight threads are available (and, therefore, blocking is free), those design patterns are completely unnecessary for writing responsive software, and, in fact, make it quite cumbersome.
Callbacks, promises and observables obliterate stack traces, make concurrency opaque, require explicit back-pressure as well as a complete "shadow" implementation of error handling and control structures beyond those provided by the language. They would all be considered anti-patterns[2] if they weren't a necessary last-resort workaround to the problem of expensive blocking (which happens to be not too hard to fix by other means).
[1]: http://en.wikipedia.org/wiki/Reactive_programming http://en.wikipedia.org/wiki/Reactive_programming
[2]: At least in non-pure languages. They do serve a purpose in referentially-transparent languages that don't have the concept of a stack or a thread, at least not in their common definition.
- deleted 12y ago[deleted]
- seanmcdirmid 12y agoIt seems to be more about ideology than theory, but theory is as overused as "reactive." React is a good example of a framework that lies outside of this: it is a simple solution for the problem that doesn't involve callbacks, promises, or even observables. My own project, Glitch, solves these problems by managing time: http://research.microsoft.com/en-us/people/smcdirm/managedtime.aspx http://research.microsoft.com/en-us/people/smcdirm/managedti... It doesn't block, it doesn't use functional abstractions either, Glitch simply replays code until all writes have seen all reads (it also doesn't requiring lifting of time-dependent values in the same way that React doesn't). Also, see: http://research.microsoft.com/pubs/230746/control.pdf http://research.microsoft.com/pubs/230746/control.pdf Which argues that we might have given up on control flow too soon. Still this isn't a bad essay for what it is, even if it isn't very general.
- pron 12y agoThose papers relate to real reactive programming (aka dataflow); the article discusses something else entirely, namely ways to write concurrent, low-latency, responsive applications. Unfortunately, it picks the more cumbersome approaches to achieve that goal.
- seanmcdirmid 12y agoYa, it is more systems than PL. See my reply to your other comment.
- cowbertvonmoo 12y agoYou are absolutely right that React accomplishes much without discrete event-driven change propagation. React falls clearly under the "behavior" style of reactivity, meaning that the state is polled to effect change. This is particularly useful in situations where change occurs more frequently than rendering, or even continuously. I talk about this toward the end of GToR.
- bkirwi 12y agoIt's worth noting that green threads are not 'enough' -- in any language with concurrency, you still need to be explicit about what work can run concurrently and what needs to be sequential. In Go, for example, the default is sequential operation; if you want to run a bunch of code concurrently, you need to do extra work to launch a bunch of new goroutines / wait for everyone to finish. In Haskell, which also (typically) has green threads, there's a popular `async` package that supplies a promise-like construct -- it's quite useful when you want to be explicit about concurrency and ordering.
- pron 12y agoOf course. Let me just clarify one point: lightweight[1] threads are not an abstraction; threads are. Lightweight threads are simply threads whose implementation is such that blocking has no (or negligible) overhead. When you have threads, you're better off using blocking queues and blocking futures, which are the "pull" duals of the "push" mechanisms described in the article. [1]: I don't like the term green threads because traditionally it's been used to describe threads that do not support parallelism.
- skybrian 12y agoI agree that goroutines have their advantages, but I think you're missing an important point about the theory. Functional programming and async I/O in single-threaded languages are closely connected. Functional programming has no built-in notion of time; conceptually, the time a pure function takes to run must not have any effect on correctness, or replacing a function call with its value would have side-effects. To allow time to pass in a way that matters for correctness, you need callbacks, and monadic types are a form of callback-based programming. In a single-threaded program, the goal is for functions to execute as quickly as possible so that the user doesn't notice pauses, so the solutions end up being similar. So these are not implementation tricks; they're fundamental to the theory of how programs execute. Erlang is built on callbacks as well since each event results in another function call. Goroutines and blocking function calls are fundamentally different. Blocking function calls need to return at the right time or it's a bug.
- pron 12y agoI specifically mentioned that in my comment. Yet, in languages that do have the concept of a thread (and do not restrict side effects), these are all anti-patterns: performing side effects in these monadic compositions is dangerous, and those compositions replicate constructs that already exist in those languages (control structures, exceptions). No one in their right mind would consider importing these Haskellist concepts to other languages were it not for the fact that blocking threads is expensive. Fixing that problem directly -- meaning, making blocking free -- is therefore the right solution.
- rektide 12y agoGTOR to me seems to be about finding intents, looking at different signallings of thing or things happening across time. You state in the first paragraph that there's a clash with how GTOR views things, and you have three paragraphs prostelytizing for greenthreading assuming that I understood the initial clash you saw, but you've provided very little context to explain the "namely, [GTOR] confuse[s] intent (or abstraction with implementation" Are you getting hung up on the fact that GTOR talks through some specific apis for reactivity? You seem very much opposed to letting someone mention callbacks, prormises or observability? But GTOR is itself about mentioning these things so we can get past them and think of reactivity more generally. Yet you seem mired in your hatred for these concepts, in a way that prevents you from seeing that the article is about building effectful processing- having code or data whose effect is the running of other code, in a general fashion. And your inability to see that generalness, your forcing some weird diatribe against non-greenthreaded systems as all missing the point, is there rooted itself in confusing an implementation with intent, for surely blocking or no, concurrent or non, code and data will create reactions amid others. I suggest getting more into the categories about. Sometimes binding happens before event, sometimes event before looking. Sometimes event is singular, sometimes it's over a duration, sometimes it's ongoing- edge, level triggering and continuous. Sometimes event has concurrency sometimes it's over time. None of these don't make sense in Erlang or any other runtime, even if you might not see them expressed as first class constructs with apis, even if the reactivity were more baked in, as Erlangs send is. Most of all, I have a very hard time understanding what your clash really is. I feel very much I'm being sold something, but the first paragraph doesn't give me a clear idea of what it is I'm being asked to accept evidence for.
- pron 12y agoMy disdain for those technique stem from their being anti-patterns in imperative languages. Performing side effects inside monadic compositions is particularly dangerous, and the only reason anyone even considers importing these techniques is because blocking is expensive, as they replicate features already found in imperative languages (control structures, exceptions). There is nothing about these that make them related to "general reactivity", mostly because there is no such thing as reactivity. They are simply techniques of performing actions in referentially transparent languages. In imperative languages, the most general, theoretically pure, fundamental construct of "reactivity" (whatever that means), is the thread (Erlang's send is not special, and not required). There is absolutely nothing more fundamental about the referentially-transparent (lambda calculus) way of doing things than the imperative way of doing things, and since the article discusses imperative languages, the LC way of doing things is potentially harmful as there is nothing to enforce referential transparency.
- platz 12y agohttp://www.slideshare.net/deanwampler/reactive-design-languages-and-paradigms http://www.slideshare.net/deanwampler/reactive-design-langua...
- spion 12y agoMany promise libraries (e.g. bluebird, Q, when) as well as some observable libraries (e.g. RxJS) successfully preserve stack traces.
- pron 12y agoIf by "preserve" you mean "recreate", just as they need to recreate exceptions and control flow. These techniques recreate imperative constructs using lambda-calculus concepts in languages that already have those constructs as fundamental building blocks. Hence, they create a full "shadow" language, that's not directly interoperable with the host language.
- spion 12y agoMy point is that the shadow language isn't really that much "second class". Would you also call using `Array#map` and `Array#filter` instead of `for` a shadow language? Not really. Well in this case e.g. with promises other than a few basic operations and if blocks the "shadow language" is really close with the "real language". Especially given the fact that the host language is pretty weak [1] and that it just got short lambda syntax that makes it less tedious to write this kind of code (arrow functions). [1]: No filtered exception handling? Just got halfway-decent `for..of` loops?
- pron 12y agoWell, I know very little JavaScript to comment, so you may well be right, and besides, as long as JS doesn't have threads, there's not much choice, really. Also, since there's no parallelism, the consequences of having side effects in monadic compositions (promises) are not as bad as in environments that do support parallelism. Still, if you can get some lightweight threads implemented in JavaScript (or green threads, in this case, as there is only no parallelism), I think you'd find them to be even better. Threads are just a better fit for imperative languages especially ones with unrestricted mutation.