inko-lang / inko

A language for building concurrent software with confidence
http://inko-lang.org/
Mozilla Public License 2.0
869 stars 38 forks source link

Implement STDOUT, STDERR and STDIN entirely in Inko #746

Closed yorickpeterse closed 1 week ago

yorickpeterse commented 3 weeks ago

Description

These types currently make use of the Rust runtime library, and wrap the Rust types. There's however no need for this:

Implementation wise I'm leaning towards not buffering STDOUT by default. With 988b72191f4aa66a3ac4f95dcf07b88634bad7de it's possible to perform buffered writes, meaning you can opt-in to buffered writes if desired, while opting out would require a separate type (e.g. STDOUT and UnbufferedSTDOUT/UnbufferedStdout?).

As part of this we should also rename these types as follows:

Blocked by

Related work

yorickpeterse commented 3 weeks ago

To add another reason for not buffering STDOUT: for certain scenarios you might want to automatically disable buffering, such as when running the program in a pipeline. For this we'd need https://github.com/inko-lang/inko/issues/634, which in turn requires more work.

yorickpeterse commented 3 weeks ago

A brief overview of what some languages do:

Language STDOUT
C# buffered
Crystal buffered, though it has a helper method for automatically flushing
D buffered
Go unbuffered?
Julia line buffered?
Node.js unsure, seems to be synchornized?
Python buffered
Rust line buffered
Swift block buffered?
yorickpeterse commented 3 weeks ago

To add to the above: while the language may do one thing, the underlying platform may do something else. For example, libc still buffers STDOUT by default unless you explicitly disable this using setvbuf().

yorickpeterse commented 3 weeks ago

Another note: if we want to ensure that STDOUT and such always use the file descriptors 0, 1, and 2, we need to first take care of https://github.com/inko-lang/inko/issues/633, such that files in Inko are just wrappers around file descriptors instead of opaque Rust values.