The term "stream" is traditionally thought of as related to I/O operations. What is the reason Java chose the term "stream" for their functional-style operations?
-
Way too broad, opinion based.markspace– markspace2015-06-05 15:18:24 +00:00Commented Jun 5, 2015 at 15:18
-
It's meant to be an etymology question - is it not worded properly? Or are etymology questions still too broad?neverendingqs– neverendingqs2015-06-05 15:23:07 +00:00Commented Jun 5, 2015 at 15:23
-
5Voting to reopen: I have an answer drafted based on Java 8 development history.Stuart Marks– Stuart Marks2015-06-05 17:40:08 +00:00Commented Jun 5, 2015 at 17:40
-
2@StuartMarks This question has been reopened.rgettman– rgettman2015-06-05 20:28:01 +00:00Commented Jun 5, 2015 at 20:28
-
1@rgettman Thanks for the notification. Answer posted.Stuart Marks– Stuart Marks2015-06-05 21:12:22 +00:00Commented Jun 5, 2015 at 21:12
2 Answers
A "stream" is not necessarily related to I/O but is a generalized concept referring to information flowing through a system.
The notion of Stream Processing (Wikipedia link by Mr.Me) having to do with SIMD processing or vector-based computing is also similar to the computational style afforded by the Java 8 Streams API.
However, I believe that the main inspiration for "streams" in Java 8 comes from this book: Structure and Interpretation of Computer Programs, 2/e. Abelson, Sussman, and Sussman. MIT Press, 1996. (This book can be read for free at its MIT Press website.)
Here are some passages from the introductory section of Chapter 3, Modularity, Objects, and State, on pp. 217-218 of my hardcover edition.
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.
Section 3.5 (Streams, pp. 316ff) contains a detailed discussion of the streams approach.
To be sure, Java 8's Streams are different from the streams introduced by SICP. But some of the fundamental concepts, such as immutability, delayed evaluation, and the flow of values through a system -- a opposed to mutating values "in-place" -- are quite similar. The notion of "grappl[ing] with time" mentioned above seems reminiscent of the issues in Java 8 Streams regarding encounter order vs. processing order.
When we were developing the system we kicked around a number of different words to describe what the library was trying to represent. We ended up using "streams" more than any other word, and it stuck.
Comments
Stream Processing is a broad concept where reactive functional programming has emerged.
the idea is to build tasks around changes in data, those changes are usually referred to as events, but every time a new data is pushed down the stream, or a change happen the tasks execute to handle that.
for example in functional reactive programming, you might want listen to a click event on a button, each time the click happens, a new object is pushed down the events stream, and you can handle it.
so even though the code you build (tasks) may not have anything to do with stream, rather than proper handling the new value. the engine/concept behind the scene is a chronicle flow of data.
which is similar to input output streams, in a sense that data flows sequentially there too.
for more: read this blog post