-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Deprecate open(filename) mode strings ("r", "w+", etc...) ? #14844
Comments
these options sounds like they are inviting all kinds of issues when dealing with anything other than local files on a posix system. option 1: option 2: option 3: |
What do other recent high-level languages do in that regard? |
The have essentially the same API that we have. I have to say I'm not entirely clear what the problem with the current interface is. If we had different types for readable and writeable IO objects, then there would be a type stability issue, but we don't have that, so... |
It is just a minor point of consistency. As far as I am aware there are no other Julia API examples of passing options to a function as little strings,
I don't want to seem dismissive, these are all real concerns. However, they are mostly implementation concerns. My reason for posting this issue is "Is there a simpler interface for this stuff?". I believe the implementation details can be solved. In fact, it is kind of the point for the systems engineers solve the implementation headaches once and hide them behind a simple API, so the scientific programmers don't have to think about them.
I guess it seems to me more like hiding, as much as possible, all the cogs and grease that make the wheel go around.
Not all examples below are recent, but there is plenty of precedence for high level languages hiding the underlying POSIX file modes. The examples below include:
|
What about changing this: open(filename::AbstractString, mode::AbstractString)
open(filename::AbstractString, read::Bool, write::Bool, create::Bool, truncate::Bool, append::Bool) to this: open(filename::AbstractString; read=true, write=false, create=false, truncate=false, append=false) Using strings of single character codes seems odd when we have kw args... Having a 5 Who will know what |
I definitely agree about replacing the five boolean version with keyword args – the |
We could potentially use EnumSet (#19470) for this. |
I'm going to remove this from the milestone; it should be easy to introduce a new syntax (since it would accept arguments of a new type) and eventually retire mode strings. |
fixed by #25696 |
#25696 deprecates positional Bools, but it does not deprecate mode strings (the subject of this issue). I don't see a pressing reason to deprecate the mode strings right now, but I think the original rationale still applies.
Perhaps leave this open for consideration along side other IO stuff that needs eventual cleanup #24526. |
Discussion of
read
andwrite
functions yielded the observation that the "w" inopen(filename, "w")
seems awkward: #14608 (comment).Thinking about this more, it seems that POSIX fopen(3) mode strings in Julia's public IO API is a bit odd. It might be preferable to deprecate them in favour of something more consistent with Julia's other APIs and to use defaults that remove the need to think about file modes in most cases.
Option 1
Always open read/write and replace "w" and "a" with new function names.
Rationale: clear and simple.
Option 2
Deprecate
open
in favour ofmmap
.Rationale: There are many things that behave like a stream (network sockets, pipes, serial ports, work queues etc...). However, local files are really much more like an array than a stream. So why not use an array interface by default for local files?
For large files,
mmap
is an obvious performance win (or for pure sequential access at least not any worse). For small files there is OS overhead in setting up the map but this could be optimised away. e.g. Julia'smmap
could cache the whole file in a memory buffer for small files.Option 3
Remove the need for files to be "opened" for common sequential use cases (assumes using Option 2 for random access cases).
For sequential read use cases an iterator could return items of a specified type:
For sequential write use cases an
append
function could be used:An internal hash table mapping filenames to recently appended file handles could make this efficient.
The overal goals is to minimise the degree to which the user has to think about file modes, opening and closing handles, when to use mmap etc...
The text was updated successfully, but these errors were encountered: