jberryman / unagi-chan

A haskell library implementing fast and scalable concurrent queues for x86, with a Chan-like API
BSD 3-Clause "New" or "Revised" License
127 stars 15 forks source link

Flipped in and out meaning #14

Closed lukehoersten closed 8 years ago

lukehoersten commented 8 years ago

We read from stdin and write to stdout. Similarly, io-streams allows you to read from InputStreams and write to OutputStreams. Unagi chans are the reverse of this. Was there a motivation to name unagi chan in and out differently? If not, would you consider flipping it?

jberryman commented 8 years ago

Yeah I see your point. I've never liked the InChan/OutChan naming. But I don't think the names from io-streams really match the semantics here either. What we really want is

newChan :: IO (Ingress a, Egress a)

A "Chan" sort of exists in the ether, and we have access to its ends. "Front" and "Back" is also common in literature on queues so that could be a possibility. I hope you don't mind if I possibly make this the more general issue of naming the "chan ends" better, and edit the title.

lukehoersten commented 8 years ago

Ingress and egress are still ambiguous. Ingress could mean "coming into my code out of the channel" or "going into the channel out of my code". It depends on the perspective. My thinking is that stdin/out established a convention (the perspective of the code/coder) and that's really the best we have to now with: convention.

But yeah, feel free to change the title of the issue.

jberryman commented 8 years ago

Ah, I see what you mean now. Huh, that doesn't fit my own mental model of what we're doing at all. Will have to stew on this, thanks!

lukehoersten commented 8 years ago

A bit of Googling and I could only find prominent examples of inStream meaning "read-from from my perspective" and outStream meaning "write-to from my perspective":

Personally Java would not convince me but it seems to be a convention going back to the 60s that spans OSs, languages and libraries.

Do you have some other basis for your mental model?

jberryman commented 8 years ago

Well, my mental model is "channel". Like a hose: you can create a new hose, and you pass around both ends. The end with the nozzle is clearly the "egress".

Your suggestion is confusing to me because "STDIN" is the name of a channel (not an end). "STDOUT" is a completely different channel. Their names come from their very peculiar function of moving data into and out of a program, and the fact that our code writes to one and reads from the other follows from that. It sounds like when you see "STDIN" you maybe think "going into my code" when I think the name means "the channel for program input".

That said I totally see what you mean now. I'm not trying to argue just unpack my own perspective and understand yours.

Further complicating things is the "stream" abstraction. To my mind a stream (in the context of Haskell, rather than e.g. the "standard io streams" we were just talking about) is something resembling a list, rather than just another word for queue or channel; there might be an associated thing you can write values to, but you don't write to a stream.

It sounds like at least not using "in" and "out" in the names might help others. On Sep 29, 2015 9:12 PM, "Luke Hoersten" notifications@github.com wrote:

A bit of Googling and I could only find prominent examples of inStream meaning "read-from from my perspective" and outStream meaning "write-to from my perspective":

Personally Java would not convince me but it seems to be a convention going back to the 60s that spans OSs, languages and libraries.

Do you have some other basis for your mental model?

— Reply to this email directly or view it on GitHub https://github.com/jberryman/unagi-chan/issues/14#issuecomment-144240895 .

reiddraper commented 8 years ago

How about Read and Write?

lukehoersten commented 8 years ago

You read from the read and write to the write? Sounds good to me.

On Fri, Oct 2, 2015 at 4:48 PM Reid Draper notifications@github.com wrote:

How about Read and Write?

— Reply to this email directly or view it on GitHub https://github.com/jberryman/unagi-chan/issues/14#issuecomment-145162636 .

jberryman commented 8 years ago

Closing this as I don't have any other names I'm enthusiastic about, and it's late in the game to change. I think it's for the next queue implementer to learn from this thread and try to come up with a better name.