In this video, learn about reactive programming and understand what it is.
- [Instructor] Hi, welcome to section one Reactive Programming. What is this section about? In this section, we will learn what Reactive programming is, its benefits, and what we can do with it. Because it can be a complex topic, we will explain everything in a really simple way. We are going to use an analogy which will make it even easier. Once we understand Reactive programming, we'll see that Reactive streams is an effort made by the community to standardize how everything is supposed to work.
Now we move on to the third video of this section that explains what Reactive programming is. By the end of the video, you should be able to understand what it means. We are going to learn qualities, how this applies to different programming languages, and how to contribute if you want to. Let's kick off. I've been repeating this question a lot. What is Reactive programming? Let's take a look at what Wikipedia says. In computing, reactive programming is a programming paradigm oriented around data flows and the propagation of change.
Let's break this down. First, what is a programming paradigm? It is a style of building the structure on elements of computer programs. Data flows are quite the same data streams. We'll understand it better later on this course, but basically, it is a sequence of ongoing events ordered in time. Instead of working with discrete objects, we work with data flows. Propagation of change, that means if something changes, the change is going to be propagated to everything that is using it.
With Reactive programming, we can express dynamic or static data flows with this. The line execution model will automatically propagate changes through the data flow. Those data flows or streams are going to be asynchronous. How is that different from Imperative programming? Let's take a look at the expression. A equals b plus c. In Imperative programming, a has been assigned the result of b plus c. In the instant, the expression is evaluated, and later the values of b and c can change, but they won't have any effect on the value of a.
However, in Reactive programming, the value of a would be automatically updated whenever the values of b and c change without the program executing the expression again. How can you use Reactive programming? You can use it with different approaches. It is possible to fuse Reactive programming with ordinary Imperative programming. In such a paradigm, Imperative programs operate on reactive data structures. What about an object-oriented approach? The most natural way to make such combination is something like in a method some field objects have reactions that automatically reevaluate when the other reactions they depend on have been modified.
You also can use it with functional programming. We'll talk more about this in section two. Let's take a look at an example to understand the propagation of change. Have you ever used a spreadsheet? I'm sure you have. It's often used as an example of reactive programming. When you define a formula in a cell, for example, let's say that the value of the cell A1 is the sum of B2 and C3. When you modify the value of one of those cells, the spreadsheets automatically react to it and calculate the new value in A1.
How can we see that happening in reactive? Imagine that there is data flow whose purpose is to reflect the state of the cell B2, and when the formation changes, then your value is sent through the flow. In the other set of the flow is supposed to be cell A1. When B2 is changed the new value is sent through a flow, and if we say A1 which calculates the sum with the value of C3. If we have the same structure with cell C3, A1 can react to changes in both cells.
This is an analogy. Spreadsheets don't work like this, but I hope you can understand how reactive programming would work in a scenario like this one. As I mentioned before, reactive programming is just a programming paradigm. Their implementations of this paradigm for different programming languages. Reactive extensions is a set of api's that brings reactive programming to different programming languages. You can use it in .NET with Rx.NET, in Java with RxJava, Scala with RxScala, and many more.
We are going to focus on RxJava in the second volume of the course. For more information, go to that website, reactivex.iu. As I said before, we are going to use RxJava later on the course. RxJava is open source, so it's still a work in progress, and they have a long list of work documented issues. You can contribute to the project. If you do, they will expect something like, you read the Rx design guidelines. You review the existing code and comply with existing partners, and you include uniqueness, obviously.
This is the end of this video. We know what reactive programming is, but why do we need it? What are the benefits? Let's talk about that in the next one. Hope to see you there.
This course was created and produced by Packt Publishing. We are honored to host this training in our library.
- What is reactive programming?
- Java 9 reactive features
- Creating and observing sources with RxJava
- Unit testing
- Akka streams in a reactive environment
- Building a sample reactive application