官术网_书友最值得收藏!

A bit of history

Before we talk about what Reactive Programming is, it is important to understand how other relevant programming paradigms influenced how we develop software. This will also help us understand the motivations behind Reactive Programming.

With a few exceptions, most of us will have been taught imperative programming languages such as C and Pascal or object-oriented languages such as Java and C++; either self-taught or at school/university

In both cases, the imperative programming paradigm of which object-oriented languages are a part dictates that we write programs as a series of statements that modify program state.

To understand what this means, let's look at a short program written in pseudocode that calculates the sum and the mean value of a list of numbers:

numbers := [1, 2, 3, 4, 5, 6] 
sum := 0 
for each number in numbers 
  sum := sum + number 
end 
mean := sum / count(numbers)
The mean value is the average of the numbers in the list, which is obtained by dividing the sum by the number of elements.

First, we create a new array of integers, called numbers, with numbers from 1 to 6, inclusive. Then, we initialize sum to 0. Next, we iterate over the array of integers, one at a time, adding the value of each number to sum.

Lastly, we calculate and assign the average of the numbers in the list to the mean local variable. This concludes the program logic.

This program would print 21 for the sum and 3 for the mean, if executed.

Though a simple example, it highlights its imperative style: we set up an application state, sum, and then explicitly tell the computer how to modify that state in order to calculate the result.

主站蜘蛛池模板: 微山县| 布尔津县| 东莞市| 浏阳市| 公安县| 西乡县| 玉环县| 尚义县| 获嘉县| 邢台县| 余干县| 南充市| 镇康县| 农安县| 南乐县| 崇仁县| 丁青县| 历史| 平度市| 永丰县| 太康县| 乌兰浩特市| 洛南县| 奈曼旗| 和政县| 中江县| 平原县| 宜黄县| 潮州市| 蕉岭县| 陆川县| 册亨县| 军事| 随州市| 饶河县| 宿州市| 灌云县| 萝北县| 隆尧县| 南川市| 个旧市|