Skip to content

Docs: Recommend read(filename, String) and write(filename, contents) instead of open #43428

@fonsp

Description

@fonsp

Julia has two super easy to use functions:

julia> write("hello.txt", "world")
5

julia> read("hello.txt", String)
"world"

That should cover file I/O needs in most cases, without having to deal with file handlers! 🎉 I think this is really useful for many (beginner) users, but not visible enough. Whenever I give this tip to a new Julia user, they react along the lines of: "If only I knew this earlier!"

We should recommend this in our docs. My suggestions:

  1. Right now, our manual entry on "Working with files" uses open(filename::String, mode::String) to create a file handler (the first handler is even left open!). Instead, this first example could use my above snippet. (Also, Working with Files could be its own chapter in the manual?) Docs: networking-and-streams: document direct read and write without streaming #49834
  2. write should have a short, simple docstring for just the write(filename::String, x) method. Docs: simple docstring for write(filename::AbstractString, x) #49835 and Docs: simple docstring for read(filename::AbstractString) #49836
  3. The docstrings for read(filename::String, args...) and write(filename::String, x) should appear more prominently in the page IO and Network, before the open function. Simple filename methods should appear before IO methods. Docs: io-network: list read(::String) and write(::String,::Any) before open #49837
  4. isfile could use the direct read and write methods. docs: isfile: direct write instead of IO #45261
  5. We could add links to read and write from the Filesystem chapter. Docs: file: list read and write again #49838

I would be happy to write this PR myself, let me know which of these points (1-5) are welcome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsThis change adds or pertains to documentationioInvolving the I/O subsystem: libuv, read, write, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions