Chris introduces you to a high-level overview of the reactive programming paradigm.
- [Instructor] All right, let's get started with reactive programming. We'll start off with a quote from Gerard Berry, whose research contributed quite a bit to the fields of functional and reactive programming. "Interactive programs work at their own pace "and mostly deal with communication, "while reactive programs only work in response to "external demands and mostly deal with "accurate interrupt handling." Reactive programming is the practice of programming using asynchronous data streams.
It's all about building async, nonblocking, and event-driven applications that can easily scale. To phrase it another way, reactive programming is an async, declarative programming paradigm concerned with data streams and the propagation of change. Now let's define what a data stream is. A stream is a sequence of ongoing events ordered in time.
Really, anything can be a stream. Variables, user input, properties, caches, data structures, and click events. For example, you can imagine Tweets with a specific hashtag as a data stream. Or a series of click events could be another data stream. A data stream can emit a value, an error, or a completed signal.
Next up, let's take a look at a stream in action. A stream emits values over time. The stream can emit zero, one, or even multiple values. It can also emit an error event or a completion signal, indicating that the stream is done emitting events. You can perform many data stream operations.
A stream can be used as input to another stream. Multiple streams can be used as input to another stream. You can merge two streams into one. You can filter a stream and you can map data values from one stream to another. Now let's take a look at using data stream operations in action. Okay, first off, let's start with our original data stream.
Next up, let's apply the map operation. The map operation will map each value to the field duration of that value. The end result of this operation will leave us with a stream of duration values. Finally, let's apply a filter operation. In this operation we will filter out values that do not meet the criteria greater than 15.
Now our final result will be a stream of duration values where the value is greater than 15. We will see later in this course all of this is able to be accomplished with a single line of functional code. Moving forward, let's take a look at some of the differences between imperative and reactive programming. Imagine the statement a equals b plus c.
While in the paradigm of imperative programming a is being assigned the result of b plus c in the instant the expression is evaluated. Later on the values of b and/or c can be changed with no effect on the value of a. Let's take another look at the statement a equals b plus c. But this time in the context of reactive programming.
The value of a is automatically updated when the values of b and/or c change without the program having to re-execute the statement. Next up, let's review some programming model terms. Synchrony is the property of a model being time synchronous or asynchronous. Determinism is the property of a model being deterministic versus nondeterministic in both evaluation process and results.
The update process can use either callbacks, data flow or actors. One other concept we will look into is the runtime graph. The runtime graph represents dependencies among reactive values. Nodes in the graph represent computation. While edges model dependency relationships. The graph keeps track of computations, which must be executed anew when an input changes value.
Okay, great. You should have a general idea of the concept of reactive programming now. In the next video we will be checking out the reactive manifesto.
- Reactive programming concepts and techniques
- Functional programming concepts and techniques
- Overview of popular reactive frameworks
- Building an RxJava application
- Building an Akka application
- Unit testing with Akka and RxJava