Closed schien closed 10 years ago
This is how streams work. You read from the output, and write to the input. Things come out of the output, and go in to the input.
This is anti-intuition I would say. May I know if we have any strong reason to do so?
I'm sorry, but your intuition is just wrong. Going back to the definition of "I/O", input is where data goes in (is written to), and output is where data comes out of (is read from).
Take Java as an example: Socket.getInputStream means you want to read some data which are "input" to your system via the socket; Socket.getOutputStream means you want to write some thing out of your system. So does cin/cout in C++ std lib. The direction of IO is mostly determined from the perspective of your system (program) instead of the socket instance.
[1] http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html#getInputStream()
That Java example is helpful. I am starting to believe I am wrong, or as you put it, I am coming from the wrong perspective. I will do some more research to convince myself, but smaug____ in IRC (who is not on GitHub) also says your perspective is the common one in computing.
So thanks. Thanks especially for persisting despite my rather snippy responses. I was a bit short because we went over this design in some detail while developing the streams spec, and nobody even brought this concern up, so I was pretty sure we had consensus. Oops.
Actually, when I started to rewrite the TCP and UDP API to be based on Streams API my intuitive feeling of input and output was according to what schien states, i.e. data direction is defined from the perspective of the application using the API. So I can interchange the names of the Readable and WritableStream attributes in the TCP and UDP Socket API. There might also be a need for some changing of wording in the Streams API specification. WDYT?
I must say for what it worth that my own intuitive expectations would be more related to the approach mentioned by @schien
Both TCPSocket and UDPSocket have following WebIDL definition:
However, the common definition in most of the programming languages will treat
output
as a stream to write something out of the system and treatinput
as a stream to receive something from out side of world. I'll suggest to interchange the type of these two attributes, which will make more sense to developers.