Do we need Win95/98/Me support?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 22 23:08:42 PST 2012


On Sunday, January 22, 2012 22:56:23 Walter Bright wrote:
> 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);

That happens anyway, because Phobos doesn't use .di files.
     
> 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.

Aside from the toMBSz issue, templatizing them costs essentially nothing on 
the implementation side and yet enables the programmer to pass in whatever 
string type they want. The only issue is that if you were using a .di file 
(which we're not, and won't, because it kills inlining and CTFE - though 
neither affects std.file much), you'd then have to have the implementation in 
the .di file whereas currently you don't.

So, as far as I can see, templatizing them costs us nothing (aside from the 
toMBSz issue) and makes the functions more flexible.

Now, I don't think that it's all that big a deal that you have to convert 
whatever string type you're using to string to pass to functions in std.file, 
but I pretty always use string anyway. Other folks have complained in the 
newsgroup about the fact that Phobos functions generally force them to use 
string specifically. So, it seemed like a no-brainer to just templatize the 
std.file functions on string type. toUTFz makes it trivially possible everyone 
but on pre-Win2K systems which have to worry about their strings being ANSI 
instead of UTF-8.

- Jonathan M Davis


More information about the Digitalmars-d mailing list