DirEntry on Windows - wstring variant?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 24 15:53:05 PDT 2014


On Friday, October 24, 2014 21:06:37 dcrepid via Digitalmars-d-learn wrote:
> As a Windows programmer using D, I find a number of questionable
> things with D's focus on using string everywhere. It's not a huge
> deal to add in UTF-8 to UTF-16 mapping in certain areas, but when
> it comes to working with a lot of data and Windows API calls, the
> less needless conversions the better.
>
> I like the DirEntries (std.file) approach to traversing files and
> folders in a directory (almost as nice as C++14's <filesystem>),
> but I think its a bit odd that native-OS strings aren't used in D
> here.  Sure, I get that having a fairly consistent programming
> interface may make using the language easier for certain
> programmers, but if you're using D with Windows, then you will be
> made well aware of the incompatibilities between D's strings and
> the Windows API (unless you always use ASCII I suppose).
>
> Anyway, I'm curious if proposing changes to those interfaces is
> worthwhile, or if I should just modify it for my own purposes and
> leave the standard library be.
>
> P.S. Its a shame to keep running into Unicode issues with D and
> Windows, and sometimes its a bit discouraging. Right before I
> peeked into DirEntry, I worked a bit on a workaround for
> stdio.File's unicode problems (a documented bug thats 2+ years
> old). I remember trying D a while back and giving up because
> optlink was choking on paths. And just yesterday it choked on
> what the %PATH% environment variable was set to, so I had to
> clear that before running it.

I don't know. The expectation is generally that programs will use string and
that wstring will be used only in the rare cases that you have to interact
directly with the Windows API. When it was suggested previously that the
various functions in std.file be templatized on string type to support other
string types, it was decided that that was unnecessary code bloat and not
worth it.

Also, given how DirEntry works internally, I'd definitely be inclined to argue
that it would be too much of a mess to support wstring unless it's by simply
converting the name to a wstring when requested (which is kind of pointless,
since you can just do to!wstring on the name if that's what you want). Making
it support wstring directly would involve a lot of code duplication, and it
would increase the memory footprint, because the structs involved would then
have to hold the path and whatnot as both a string and wstring. So, I question
that it's at all worth it to try and make dirEntries support wstring. And we
definitely don't want to encourage the use of wstring. It's there for when you
need it (which is great), but programs really should be using string if they
don't actually need to use wstring or dstring.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list