gpt4 book ai didi

java - 为什么 Java 8's functional-style constructs called "流”?

转载 作者:行者123 更新时间:2023-12-02 09:05:57 25 4
gpt4 key购买 nike

术语“流”传统上被认为与 I/O 操作相关。 Java 选择“流”一词来表示其函数式操作的原因是什么?

最佳答案

“流”不一定与 I/O 相关,而是一个广义概念,指的是流经系统的信息。

Stream Processing的概念(维基百科链接 Mr.Me )与 SIMD 处理或基于 vector 的计算有关也类似于 Java 8 Streams API 提供的计算风格。

但是,我相信 Java 8 中“流”的主要灵感来自于这本书:计算机程序的结构和解释,2/e。 Abelson、Sussman 和 Sussman。麻省理工学院出版社,1996 年。(这本书可以在 MIT Press website免费阅读。)

以下是我的精装版第 217-218 页上的第 3 章“模块化、对象和状态”的介绍部分的一些段落。

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,第 316ff 页)包含对流方法的详细讨论。

可以肯定的是,Java 8 的 Stream 与 SICP 引入的流不同。但一些基本概念非常相似,例如不变性、延迟评估和系统中的值流动(与“就地”改变值相反)。上面提到的“grappl[ing] with time”的概念似乎让人想起 Java 8 Streams 中关于遇到顺序处理顺序的问题。

当我们开发系统时,我们使用了许多不同的词语来描述图书馆试图表达的内容。我们最终使用“流”比任何其他词都多,并且它被卡住了。

关于java - 为什么 Java 8's functional-style constructs called "流”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30670011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com