Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readLine and readLineSlice as methods to InStream #3822

Open
jayschwa opened this issue Dec 1, 2019 · 4 comments
Open

Add readLine and readLineSlice as methods to InStream #3822

jayschwa opened this issue Dec 1, 2019 · 4 comments
Labels
standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@jayschwa
Copy link
Sponsor Contributor

jayschwa commented Dec 1, 2019

std.io.readLine and friends are top-level functions that read from the stdin stream or passed-in stream. InStream already has a wide variety of methods on it, and it seems inconsistent that readLine would be top-level functions, while all the other readFoo-style functions are methods on InStream.

If implemented, the top-level readLine functions could become wrappers for the new methods, and eventually be deprecated and removed.

One of the nice things that readLine does is DRY the getStdIn().inStream().stream ceremony. Proposal #3823 addresses that.

@MasterQ32
Copy link
Contributor

readLine ist just a special case of InStream.readUntilDelimiterAlloc or InStream.readUntilDelimiterBuffer

See:

pub fn readUntilDelimiterAlloc(self: *Self, allocator: *mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {

pub fn readUntilDelimiterBuffer(self: *Self, buffer: *Buffer, delimiter: u8, max_size: usize) !void {

I think it's better this way as with a readLine-Function, the zig std will assume a defined "newline sequence" which may not be the same on all environments

@jayschwa
Copy link
Sponsor Contributor Author

jayschwa commented Dec 1, 2019

readLine ist just a special case of InStream.readUntilDelimiterAlloc or InStream.readUntilDelimiterBuffer

Agreed, but why does it make sense for readLine to be standalone and for readUntilDelimeter to be a method? readUntilDelimeter and many other readFoo-style methods could just as easily be standalone functions like readLine, but they aren't, so what is the distinction?

the zig std will assume a defined "newline sequence" which may not be the same on all environments

I don't follow. How is the assumed newline sequence a point in favor of standalone function versus method?

@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Dec 1, 2019
@andrewrk andrewrk added this to the 0.7.0 milestone Dec 1, 2019
@andrewrk
Copy link
Member

andrewrk commented Dec 1, 2019

I see why this was problematic now, but std.io.readLine is named after GNU readline and is intended for the use case of an interactive command line, rather than streams. (There is a lot more work that would need to go into this API before it is fully functional, so it's understandably confused with a simple stream line reader)

@daurnimator
Copy link
Collaborator

FWIW this will all get much cleaner if the stream mixin concept is integrated. Currently discussion of Mixins is going on in #3785

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@IridescentRose IridescentRose mentioned this issue Nov 4, 2022
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants