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

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.

主站蜘蛛池模板: 喀喇| 称多县| 兴业县| 临西县| 西华县| 嵩明县| 沂水县| 隆安县| 岫岩| 鸡西市| 荥阳市| 神木县| 康马县| 鸡东县| 台东县| 富阳市| 陆川县| 微博| 石阡县| 长丰县| 宁夏| 扶绥县| 黄大仙区| 舟曲县| 加查县| 洪江市| 梁山县| 三明市| 吴江市| 宜州市| 台前县| 东乡县| 军事| 白银市| 宁波市| 轮台县| 凤城市| 綦江县| 定日县| 新乐市| 治县。|