|Posted by Nick Sabalausky||PermalinkReply|
Summary: Make raw write mode the default
--- Comment #0 from Nick Sabalausky <firstname.lastname@example.org> 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:
void transform(string str)
/+ ...perform some modification of 'str'... +/
auto str = cast(string) read(args);
str = transform(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: -------