Deprecating things without a replacement

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jul 17 09:13:46 PDT 2011


On 17.07.2011 19:28, Robert Clipsham wrote:
> I've just begun updating my code to work with 2.054 and noticed that
> quite a few things have been deprecated - some without a decent
> replacement. Could the phobos team not make a habit of this please?
>
> Example:
>
> Before:
> ----
> foreach (file; listDir(".", "*.d") ~ listDir("./foo/", "*.c"))
> {
>     // Do something
> }
> ----
> After (sorry about the awkward indentation):
> ----
> void doSomething(string file)
> {
>     // Do something
> }
> foreach (string file;
>              filter!`endsWith(a.name,".d"))`(
>                         dirEntries(".",SpanMode.depth))
> {
>    doSomething(file);
> }
>
> foreach (string file;
>              filter!`endsWith(a.name,".c")`(
>                         dirEntries("./foo/",SpanMode.depth))
> {
>    doSomething(file);
> }
> ----
> Also note that you can't use dirEntries() ~ dirEntries() or
> chain(dirEntries(), dirEntries()) as DirIterator is not a range.
>
DirIterator is a range as of 2.054. And as being responsible for this 
little upgrade let me show how to fix  dirEntries() ~ dirEntries() 
problem e.g.:

auto a = array(map!"a.name"(dirEntriies("."))); // does give you an 
array of file names

And definitely you should be able to chain them :)

Combining map and filter to archive your goal seem like a long way to 
solve a simple problem, but IMO it's not that bad and far more flexible.
It might be a good idea to just make listDir to be this one-liner under 
the hood, I wasn't behind the  whole deprecation idea.

> If things in phobos are going to be deprecated, could you make sure
> that a decent replacement for *all* use cases is in place before hand?
>
> It would also be nice to add into the documentation how to use the
> replacement functions to the same effect - it took me forever to
> figure out how to replace listDir with dirEntries.
>


-- 
Dmitry Olshansky



More information about the Digitalmars-d mailing list