Reactive programming is a programming paradigm whereby programs are internally represented by a dependency graph, which is used to automatically (re)compute parts of a program whenever its input changes. In practice reactive programming can only be used for some parts of an application: a reactive program is usually embedded in an application that is still written in ordinary imperative languages such as JavaScript or Scala. In this paper we investigate this embedding and we distill "the awkward squad for reactive programming" as 3 concerns that are essential for real-world software development, but that do not fit within reactive programming. They are related to long lasting computations, side-effects, and the coordination between imperative and reactive code. To solve these issues we design a new programming model called the Actor-Reactor Model in which programs are split up in a number of actors and reactors. Actors and reactors enforce a strict separation of imperative and reactive code, and they can be composed via a number of composition operators that make use of data streams. We demonstrate the model via our own implementation in a language called Stella.
翻译:响应式编程是一种编程范式,其中程序内部由依赖图表示,当输入发生变化时,该依赖图用于自动(重新)计算程序的各个部分。在实践中,响应式编程只能应用于应用程序的某些部分:响应式程序通常嵌入在仍使用普通命令式语言(如JavaScript或Scala)编写的应用程序中。本文研究了这种嵌入方式,并提炼出"响应式编程的棘手问题"作为三个关注点,这些关注点对于现实世界的软件开发至关重要,但无法在响应式编程框架内得到良好解决。它们涉及长时间运行的计算、副作用以及命令式代码与响应式代码之间的协调。为了解决这些问题,我们设计了一种名为Actor-Reactor Model的新型编程模型,其中程序被拆分为多个actor和reactor。Actor和reactor强制实现了命令式代码与响应式代码的严格分离,并且可以通过一系列利用数据流的组合算子进行组合。我们通过自己实现的一种名为Stella的语言来演示该模型。