为什么 Java 8 的函数式结构称为 "streams"?
Why are Java 8's functional-style constructs called "streams"?
术语"stream"传统上被认为与I/O操作相关。 Java 选择术语 "stream" 作为其函数式操作的原因是什么?
Stream Processing 是一个广义的概念,反应式函数式编程已经出现。
这个想法是围绕数据的变化构建任务,这些变化通常被称为事件,但每次新数据被推送到流中,或者发生变化时,任务都会执行以处理它。
例如在函数式响应式编程中,您可能想要监听按钮上的点击事件,每次点击发生时,都会将一个新对象推送到事件流中,您可以处理它。
所以即使您构建的代码(任务)可能与流无关,而不是正确处理新值。 engine/concept 幕后是数据流的编年史。
这类似于输入输出流,从某种意义上说,数据也按顺序在那里流动。
“流”不一定与 I/O 相关,而是指流经系统的信息的广义概念。
Stream Processing (Wikipedia link by ) 与 SIMD 处理或基于向量的计算有关的概念也类似于 Java 8 Streams API.
不过,我相信 Java8 中“流”的主要灵感来自这本书:计算机程序的结构与解释,2/e。阿贝尔森、萨斯曼和萨斯曼。麻省理工学院出版社,1996 年。(这本书可以 免费 在其 MIT Press website 阅读。)
这是第 3 章介绍部分的一些段落,模块化、对象和状态, 我的精装版第 217-218 页。
In this chapter we will investigate two prominent organizational strategies arising from two rather different "world views" of the structure of systems. The first organizational strategy concentrates on objects, viewing a large system as a collection of distinct objects whose behaviors may change over time. An alternative organizational strategy concentrates on the streams of information that flow in the system, much as an electrical engineer views a signal-processing system.
...
The difficulties of dealing with objects, change, and identity are a fundamental consequence of the need to grapple with time in our computational models. These difficulties become even greater when we allow the possibility of concurrent execution of programs. The stream approach can be most fully exploited when we decouple simulated time in our model from the order of the events that take place in the computer during evaluation. We will accomplish this using a technique known as delayed evaluation.
第 3.5 节(Streams,第 316 页)包含对流方法的详细讨论。
可以肯定的是,Java8的Streams与SICP引入的streams不同。但是一些基本概念,例如不变性、延迟评估和价值在系统中的流动——与“就地”改变价值相反——是非常相似的。上面提到的“grappl[ing] with time”的概念似乎让人想起 Java 8 Streams 中关于 encounter order vs. processing order[= 的问题33=].
当我们开发这个系统时,我们使用了很多不同的词来描述图书馆试图表达的内容。我们最终使用“流”的次数超过了任何其他词,并且它卡住了。
术语"stream"传统上被认为与I/O操作相关。 Java 选择术语 "stream" 作为其函数式操作的原因是什么?
Stream Processing 是一个广义的概念,反应式函数式编程已经出现。
这个想法是围绕数据的变化构建任务,这些变化通常被称为事件,但每次新数据被推送到流中,或者发生变化时,任务都会执行以处理它。
例如在函数式响应式编程中,您可能想要监听按钮上的点击事件,每次点击发生时,都会将一个新对象推送到事件流中,您可以处理它。
所以即使您构建的代码(任务)可能与流无关,而不是正确处理新值。 engine/concept 幕后是数据流的编年史。
这类似于输入输出流,从某种意义上说,数据也按顺序在那里流动。
“流”不一定与 I/O 相关,而是指流经系统的信息的广义概念。
Stream Processing (Wikipedia link by
不过,我相信 Java8 中“流”的主要灵感来自这本书:计算机程序的结构与解释,2/e。阿贝尔森、萨斯曼和萨斯曼。麻省理工学院出版社,1996 年。(这本书可以 免费 在其 MIT Press website 阅读。)
这是第 3 章介绍部分的一些段落,模块化、对象和状态, 我的精装版第 217-218 页。
In this chapter we will investigate two prominent organizational strategies arising from two rather different "world views" of the structure of systems. The first organizational strategy concentrates on objects, viewing a large system as a collection of distinct objects whose behaviors may change over time. An alternative organizational strategy concentrates on the streams of information that flow in the system, much as an electrical engineer views a signal-processing system.
...
The difficulties of dealing with objects, change, and identity are a fundamental consequence of the need to grapple with time in our computational models. These difficulties become even greater when we allow the possibility of concurrent execution of programs. The stream approach can be most fully exploited when we decouple simulated time in our model from the order of the events that take place in the computer during evaluation. We will accomplish this using a technique known as delayed evaluation.
第 3.5 节(Streams,第 316 页)包含对流方法的详细讨论。
可以肯定的是,Java8的Streams与SICP引入的streams不同。但是一些基本概念,例如不变性、延迟评估和价值在系统中的流动——与“就地”改变价值相反——是非常相似的。上面提到的“grappl[ing] with time”的概念似乎让人想起 Java 8 Streams 中关于 encounter order vs. processing order[= 的问题33=].
当我们开发这个系统时,我们使用了很多不同的词来描述图书馆试图表达的内容。我们最终使用“流”的次数超过了任何其他词,并且它卡住了。