-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 File.writeAsLines/writeAsLinesSync methods #42424
Comments
The var out = file.openWrite();
for (var line in lines) out.writeln(line);
out.close(); so the need for a single For Admittedly, Adding any method to any interface is currently a breaking change, so adding the method will probably only happen if we consider having it worth the cost. With the rather easy workaround above, I wouldn't be too optimistic either. If we ever rework the |
But it could be done as an extension? |
Sure. I'm not particularly fond of simply adding extensions methods for anything that we might want to add to an API that we control ourselves. (Now, if we had interface default methods, I'd be much happier adding some of those, and changing existing methods to be such, because that would be a backwards and forwards compatible change where all the methods are still instance methods). |
I follow the sentiment. We did not have extensions before 2.x. One could argue that Are there technical disadvantages to
I had not heard of these before. Is there a proposal for this already? |
Not a proposal as such, but there is a request. |
File
hasreadAsBytes
andwriteAsBytes
,readAsString
andwriteAsString
, andreadAsLines
but no correspondingwriteAsLines
.It might seem like it'd be trivial to instead use
writeAsString(lines.join('\n'))
. However:The output from
writeAsString(lines.join('\n'))
might not technically qualify as a "text file" according to the POSIX definition. POSIX defines a "text file" to be a collection of lines, and a line is defined as having a newline terminator. (Also see https://unix.stackexchange.com/questions/446237/ and https://stackoverflow.com/questions/729692/.)If
writeAsLines
would be considered trivial, then the same argument could have applied toreadAsLines
. (For similar reasons regarding a final newline,readAsLines
is not quite the same asreadAsString().split('\n')
.) Arguably it's more important for reading to be tolerant and for writing to be strict, which implies that there should be a standard way of writing text files.(I know I'm being pedantic; I'm not particularly optimistic about this being addressed.)
The text was updated successfully, but these errors were encountered: