sysapps / tcp-udp-sockets

Raw sockets API
86 stars 25 forks source link

Interchange the type of input/output attribute in both TCPSocket and UDPSocket #69

Closed schien closed 10 years ago

schien commented 10 years ago

Both TCPSocket and UDPSocket have following WebIDL definition:

    readonly    attribute ReadableStream  output;
    readonly    attribute WriteableStream input;

However, the common definition in most of the programming languages will treat output as a stream to write something out of the system and treat input 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.

domenic commented 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.

schien commented 10 years ago

This is anti-intuition I would say. May I know if we have any strong reason to do so?

domenic commented 10 years ago

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).

schien commented 10 years ago

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()

domenic commented 10 years ago

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.

ClaesNilsson commented 10 years ago

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?

AMorgaut commented 10 years ago

I must say for what it worth that my own intuitive expectations would be more related to the approach mentioned by @schien