Naming Bi-Directional Streams In an API?
DingoTango writes "My coworker and I are designing an infrastructure API to manage data streams. It will allow a client developer to set up streams going to and from some invoked server functionality, and allow a server developer to write services that both consume and produce streaming data. Our quite civil disagreement involves naming: From the perspective of the client platform, the client's output stream goes to the server, and input stream comes from it. For the purpose of any ensuing discussion, let's call this the 'Local' perspective. However, if the client developer considers the service to be a widget, then the stream going to the service is the input stream and the stream coming from it is the output. Let's call this the 'Widget' perspective. As this is an infrastructure utility, we aren't able to name the streams according to function. What say ye, Slashdot? Is there any precedence, experience, or ungrounded yet vociferous opinion that will resolve this for us?"
Use foo and bar. Everyone understands that.
Why not call them the "client to server" stream and the "server to client" stream?
no lol
Name one stream "first" and the other one "post"
Why not upstream/downstream or upload/download?
Look at the purpose of the streams. Possible options are "request"/"reply", "control"/"media", etc.
The object that initiates the stream is called a "client" and the object that accepts that stream is the "server". If anyone has trouble with such simple notions then they should be selling used cars and not writing software.
UploadStream: data goes to a server.
DownloadStream: data goes from the server.
How about the upload stream and the download stream? Upload and download is usually understood to mean from the client's perspective.
Transmitting to the server is uploading. The direction from the client to the server is the uplink direction.
Just as described in some of the prior posts, I'd prefer UploadStream and DownloadStream. But if for some reason you don't want to use those names, how about StreamToServer and StreamToClient ?
Look from each component and the input and output streams based on that.
The client's output stream is the server's input stream, the server's output stream is the client's input stream.
The widgets output is the clients input and the widget's input is the clients output.
Yeah...
The syntax from socket programming, like send, receive, and listen, seems well suited for situations where both sides can act as clients or servers. Both sides would use the same syntax, each naming things from its own perspective.
...I think you want StackOverflow which is a few clicks that way ------>
Use names that don't reflect any meaning, this is usually the safest way.
:) Or since you probably have to sell it to morons on higher pay, pick something more conservative. Even colours can work, eg. Red and Green - good enough for Prolog and Quarks! :)
This applies to any graph where there is no obvious master/slave, server/client, upstream/downstream, initiator/follower relationship, ie. the relationship depends on a momentary viewpoint.
Use 'Ken' and 'Barby' if you like
...but the SEND/RECEIVE pins between modem and computer are always named from the perspective of the computer. There's precedent to use server-centric nomenclature.
Matthew G P Coe
http://mgpcoe.blogspot.com/
I can definitely the benefit of names pairs such as "Upload"/"Download" or "toServer/toClient" or "toServer/fromServer". Those all work when you've got a clear client/server orientation. But, if you're talking about more distributed situations where you have more of a peer orientation, those break down.
If you can name them separately in the client and in the server, why not use names that are meaningful to the local context? For example, the client's output stream goes to the server's input stream, and vice versa? You've got good precedent for that today in UNIXland with stdin and stdout. Consider a pipe: One side writes to its stdout, and the other side reads it from stdin. Seems perfectly logical to me.
Program Intellivision!
Call them "Bweryang" and "Bob".
although "eat me" "drink me" is a close second
Why don't you just use Java syntax? An InputStream is input on client and server side, and an OutputStream is the opposite. For what purpose do they need to be named the same on each side?
why not produce(er) and consume(er) as in the messaging world?
or is that too obvious?
Mission: To provide products that consume time and energy as entertainingly as permitted by the laws of thermodynamics.
Try a nice acronym.
from the client's programming perspective:
Client -> Server traffic or c2s (as cts is used in some old modem serial packet stuff)
Client Client s2c
Server - Client sfc
With this scheme, the programmers at either end wont get confused. Just identify who
you are, send, receive.
If no one perspective adds more benefit, flip a coin, document and stick to your decision
Media frameworks such as DirectShow, GStreamer and the such are quite good at this. I work on this specific type of code all day long and maintain my own alternative for extremely high bit-rate environments.
You're talking about designing an object that consumes and produces real-time data. The source of this data is provided by an "upstream" component (or object to be consistent) within your processing pipeline. The destination for the data produced is provided to a "downstream" object.
An API for this type of component should always been seen from the perspective of the user of the component or object. Therefore the interfaces should be named NOT from their internal perspective, but from their external perspective. After all, your APIs are theoretically there so that someone else can use your component without being familiar with the internal architecture of the component itself.
An upstream component which provides data to downstream components are "Data Sources".
A downstream component which consumes data provided by "Data Sources" are "Data Sinks"
A component which acts on data received from an upstream "data source", alters it or produces new data from to send down stream to a "data sink" is called a "transformation" object.
So, a processing pipeline should consist of 3 elements.
1) Data source
2) Transformation Object
3) Data sink
This is similar in nature to :
1) Input
2) Process
3) Output
Though in an object oriented model making use of a pipeline style pattern, it's best to name the objects appropriately.
The output of an object, or the API of an object which provides data to downstream elements, components, objects (etc) should be referred to as Source. So a "Source Object" outputs its data through a "Source". In GStreamer for example, you would say "The source element provides data to downstream elements through one of its source pins" as GStreamer (like other pipeline architectures) provides a uniform interface for providing and consuming data.
The input point of an object (which receives data from upstream objects) should be called a "Sink".
A transformation element contains a minimum of one source and one sink. Data is received by the object via its sink and the processed data is pushed from the object via its source.
This methodology is very simple to use and understand.
An alternative can be "Receiver" which suggests the object received media via this interface and "Transmitter" which suggests that the object transmits data from the interface.
Some people like to use "Listener", "Observer" etc... but since there's no nice corresponding opposite to either of these, I find them grotesque when I encounter them in code.
I think that if you read up on the GStreamer documentation web site, you'll get some great ideas for how best to handle this. Just remember that when you're providing an API to a customer, you're delivering something that should be easy to use and understand from their perspective from the outside. Your API naming should reflect this.
.... Sink and Source?
The ingress stream flows in to the network. The egress stream exits the network.
name them from the perspective from which they're used from the api. that is, functions that take data to be sent elsewhere would be named 'send'(or upload) and 'get','receive' or similar would be the other direction.
but this seems like a case of where they should have just named them john1 and doe3 or _anything_ so they could have moved on with their design, if things go this way then next week they can argue about package names.
world was created 5 seconds before this post as it is.
The server just happens to be a well know location for a service that can be connected to. The client initiates the connection. Once the connection is establised the "server" and the "client" effectively become "clients" of each other, when the output of one is plugged into the input of the other.
For example, in .net land (it's where I am, forgive me) you have a TcpListener on the server side. Then when a client connects using a TcpClient, the server creates a corresponding TcpClient on the server side. Writing to the client's TcpClient.Stream will allow you to read from the servers TcpClient.Stream, and vice versa.
Your API should probably be considering the establishment of the connection, rather than the connection itself.
Rocket science is easy. Neurosurgery, now *that's* difficult.
Pick a convention, stick to it - unless it proves obviously wrong/confusing - and move on....
Just my 2cents.
You guys are setting up a post for a story about naming conventions, when we have so many other news posts that could take precedence.... ...here is one, whatever the providing server's owner decided....as it is they that pay the bills for the server and the in house development, so if they feel like calling the service or widget, porky_pig-IS**my_(FRIEND)....who cares....
When both sides produce and both sides consume, the words "producer" and "consumer" aren't exactly as appropriate.
Think of use cases. What are the clients of your API be doing the most?
What choice will cause the least astonishment to your users?
This is a usability problem. Do what will confuse your user the least. Ask them if you have to.
Write code for both cases against your API. Use it and see what works and what doesn't.
There is no easy answer, this is a design question and aesthetics matter, hence it's rather subjective.
In any case, take into account if your target development platform uses any conventions, and if so stick to them.
In Wireless, we call the path toward the client the "forward link", and the one from the client the "reverse link". Sounds similar to your situation.
It's so simple if you follow this one simple principle: Input is what you put in and output is the result.
I have 3 questions:
1) Why isn't this the highest modded comment in the thread?
2) Why are others continuing to post after this solution? I mean, why would you do anything other than name the stream coming in to the server as the input stream in the server context, the stream coming from the client as the output stream in the client context, and so on?
3) How long until the entire project crashes in complete disaster? Does it really take 2 developers to figure this out? The only other scenario I can think of is the grown ups are finishing the project while these 2 kids are on a snipe hunt.
I just can't decide what color to paint it.
Does it really take 2 developers to figure this out?
No, one developer on their own would have figured it out. It takes two developers to make it an issue. ;c)
At first, I didn't understand what all the fuss was about, because I gathered that the server functionality always behaved like a filter. If that is the case, then just treat it like a black box; don't even muddy the waters with the fact that this box is doin' its thing "out" on a server somewhere else. The stream I feed it is 'in', the stream it gives me back is 'out'. No big deal, whether I am developing the client or the server.
But if the client will sometimes send a stream off, expecting nothing in return, then maybe 'in' doesn't make sense? I dunno. It is a convention. People establish conventions so that semantics are predictable, and good conventions align with the user's intuition. If the intuition of users or developers happens to clash, then they ought to just pick something and be done with it, then get accustomed to it. If it moves things along, I am of the crowd that says, "Call one way 'TweedleDum' and the other 'TweedleDee' and get on with your lives."
Words give you power.
I have not used it, but I think that OSCgroups does some related things with passing messages and streams to disparate clients and servers, and if one roots through the codebase it is possible that there might be some interesting conventions there.
... so just pick one and stick to it.
I'm partial to "input" and "output" myself, from the perspective of the object using them (so a client's output goes to the server's input and vice-versa).
If you need to reference both objects' streams at the same time, you've got "myInput", "myOutput", "hisInput", and "hisOutput" for clarity.
Or just pick something fun; "spinwise" and "widdershins" isn't bad, but may confuse your users.
Bravery is not a function of firepower.
~J.C. Denton (Deus Ex)
that would be much clearer than "in" and "out" and shorter than "UploadStream" and "DownloadStream"
The InputStream is the one being read from and the OutputStream is the one bing written to. The same stream will be called both depending on which side you're looking at.
I think I see your dilemma. If I understand correctly, you are examining the perspective of the client developer that might approach the server in client-server mode, in which case upStream/downStream (or something of that nature) would work nicely. Conversely, the client developer might be working with a widget that appears to him/her as any other client side object. In this case you can use in/out terminology and simply forward the call to the up/down methods respectively. Interesting names could also be ears/mouth, mike/speaker, reader/writer, etc.
sigo ergo sum