Replies: 4 comments 24 replies
-
Is this really necessary? My impression is that other languages generally don't do this, and it leads to issues like not being able to read Unicode input from the terminal on Windows. |
Beta Was this translation helpful? Give feedback.
-
What differentiates streams from ranges? If I'm writing something like a parser, what rules or guidelines should I use to decide whether to use the stream interface or the range interface? |
Beta Was this translation helpful? Give feedback.
-
Or me, since this is Phobos. |
Beta Was this translation helpful? Give feedback.
-
I have a bit of comments about the proposed package structure with regards of the IO modules. First, in my opinion If we do that, I think it means nothing else in I also suspect |
Beta Was this translation helpful? Give feedback.
-
I wanted to talk about possibilities for io. @jmdavis asked me what I thought about io, and I said I'd take a look here.
These are my thought on it, and I'm also OK with not doing any of this, and just doing it on my own packages.
D i/o is currently based on C i/o.
This is very limiting, and precludes doing things like event-loop based i/o. Walter, Andrei and I have discussed this in the past, and I had a very sketchy scheme that I planned to implement a long time ago when I thought I could replace Phobos i/o with what would eventually become iopipe. But I think phobos v3 has a real shot at doing this. What I would propose is:
FILE *
, but doesn't have to.File
structure. This structure should be exclusively D i/o. You should not pay the penalty of using C i/o with the defaultFile
infrastructure.Some examples of WTF moments with D and std.stdio:
File
instances require locking, even if they aren'tshared
.File
for pipes! The API is terrible for this, and the buffering mostly gets in the way, especially on the write side.File
. So abstracting networking with disk i/o requires wrappers not present in Phobos.File
is primarily text-based. Many files have nothing to do with text. UsingFile
on binary files is clunky to say the least.Async i/o is critical
Making it easy to do asynchronous i/o is a must for any programming language designed for servers.
Packages such as vibe, arsd, photon, and mecca all use an event loop (possibly others). I also plan on writing my own, as I find vibe eventcore to be too complex to deal with.
In order for these packages to all work together, they need to be a common implementation. If not a common implementation, then you must pick one implementation and only use packages built for it.
An event loop does a lot more than just i/o. Timers and other events (such as UI events) are also relevant.
Many languages (javascript, swift, C#, etc.) all have a basic batteries-included event loop system. async/await features depend on it being part of the language.
I think the gold standard here is a callback-based event loop, with Fibers to allow writing synchronous-looking code. Stackless coroutines are also possible, but I haven't explored that yet.
My projects
I currently have inherited Martin Nowak's io package (ambitiously packaged as
std.io
), which has cross-platform low-level io primitives. The concept was to provide a basic simple low-level i/o that could be built upon with buffers, formatting, etc. The plan was originally to provide multiple i/o "drivers", but I think at this point I will remove that possibility, and pick just async or sync i/o based on what you are doing. This will remove a lot of the complexity currently there.I also have my iopipe library, which is somewhat low-level, but I think has the right abstraction for dealing with streams.
The jsoniopipe library is a json parser which provides a stream agnostic way of parsing JSON. The idea is, it shouldn't matter how you make your stream, there should be a way to parse it. This includes normal arrays, which provide an easy way to test things. Your code stays the same, you just swap out the pieces. I envision a whole fleet of parsers that are built this way, and then you can plug them together however you want. I also intend to rework this project so the json parser simply produces an iopipe of json tokens that can be treated the same as any other iopipe (I had a blog post about this recently: https://www.schveiguy.com/blog/2023/06/new-iopipe-abstraction-segmentedpipe/)
In general the iopipe concept I view as ranges, but for streams. I would love to see Phobos adopt this.
Beta Was this translation helpful? Give feedback.
All reactions