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

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.

主站蜘蛛池模板: 屏南县| 洮南市| 阿城市| 漳平市| 祁东县| 和田市| 上高县| 抚松县| 霞浦县| 广灵县| 海晏县| 高要市| 汪清县| 花莲市| 桑日县| 清水县| 周宁县| 洮南市| 阿勒泰市| 内丘县| 咸丰县| 汨罗市| 贵德县| 翁牛特旗| 靖安县| 什邡市| 澄江县| 江门市| 临夏县| 盐源县| 苏尼特左旗| 桂林市| 芷江| 抚州市| 砀山县| 长沙市| 左云县| 江永县| 马龙县| 广平县| 五寨县|