On 1/22/2012 9:06 PM, Jonathan M Davis wrote:
On Sunday, January 22, 2012 20:58:33 Walter Bright wrote:
Why make std.file support wchar and dchar? You triple the number of
functions, all for rarely used cases, and one where the user can trivially
convert wstring to string at the call site.
It doesn't triple the number of functions. You just templatize them. You only
get triple the number of functions if you actually use them with all 3 string
types. But we've had complaints in general about Phobos functions only
supporting string rather than char[] or wstring or whatever. Templatizing
std.file's functions on string types helps alleviate that. And on Windows, it
would even allow you to pass a wstring without having to convert to a string
first and then back to a wstring to pass to the Windows API functions, which
could reduce that number of string operations required for file operations.
Regardless, the idea is to make the functions more flexible. They don't _need_
to be restricted to string specifically.
Templatizing is not the answer. The operating system file APIs take only wchar[]
(Windows) and char[] (every one else). That means that two of the three will be
nothing more than wrappers, anyway.
Doing it as templates that means that any user of std.file has to read in the
entire implementation of it, and everything std.file imports, rather than simply:
void[] read(string filename);
And yet nothing is accomplished, because two of the three will *necessarily* be
wrappers.
It's not an efficiency consideration because the conversion cost is meaningless
next to the cost of opening a file.
This triples the number of functions in practice, and becomes what I dread - a
library that is miles wide and an inch deep. We need *depth*, not trivia. These
one line wrappers are *trivia* because they take longer to look up the
documentation for than simply converting the string yourself as necessary.
Trivia does not belong in Phobos.
Another way of looking at it is Phobos should provide snap-together building
blocks, not trivial combinations of them.