| |
| Posted by Nick Sabalausky | PermalinkReply |
|
Nick Sabalausky
| http://d.puremagic.com/issues/show_bug.cgi?id=9776
Summary: Make raw write mode the default
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody@puremagic.com
ReportedBy: cbkbbejeap@mailinator.com
--- Comment #0 from Nick Sabalausky <cbkbbejeap@mailinator.com> 2013-03-21 07:55:05 PDT ---
On Windows, the "write*" functions automatically convert \n to \r\n. This is both error-prone and completely unnecessary on all versions of windows that DMD/Phobos supports (ie, at *least* as far back as XP).
On all such versions of Windows, the command line, BATch files and code editors all handle \n perfectly fine. If there are any obscure situations where \r\n is still expected, they are more properly handled as-needed as special cases.
The big-prone nature of non-raw write is demonstrated in this straightforward code:
--------------------------------------
import std.file;
import std.stdio;
void transform(string str)
{
/+ ...perform some modification of 'str'... +/
return str;
}
void main()
{
auto str = cast(string) read(args[1]);
str = transform(str);
write(str);
}
--------------------------------------
That simple code is *wrong*:
It works correctly for all input on Unix: Output newlines match input newlines. Always. The code never asks for newlines to be messed with, and therefore they never are.
But on Windows the behavior is just plain weird: Unix-style newlines in the input are silently and forcefully converted to Windows-style newlines behind the user's back. And even worse yet, *Windows*-style newlines on the input are converted to a bizarre "Mac9 plus Windows-style" combination of "\r\r\n" (not only is that wrong period, but this sequence is often interpreted as two newlines which makes it even worse). Using rawWrite fixes the problem, and creates *no* problem.
People have been caught by that bug on various occasions, such as: https://github.com/repeatedly/mustache-d/issues/3
See also the discussion on this matter on the D newsgroup: http://forum.dlang.org/post/20130320103418.00005416@unknown
Various people have agreed, and so far, there hasn't been anyone arguing to keep the current behavior.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
|