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

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.

主站蜘蛛池模板: 都匀市| 措勤县| 仁怀市| 新建县| 巩义市| 玉林市| 镇坪县| 乌审旗| 连江县| 田阳县| 荔波县| 岳阳市| 兴宁市| 陆河县| 安庆市| 定远县| 盘山县| 柳河县| 北安市| 临清市| 平潭县| 孟村| 河东区| 黎平县| 永昌县| 商河县| 宁海县| 藁城市| 新野县| 靖江市| 廊坊市| 曲水县| 渑池县| 深泽县| 五寨县| 修武县| 佛教| 卫辉市| 孟村| 齐齐哈尔市| 久治县|