digitalmars.D - Deprecating things without a replacement
- Robert Clipsham (40/40) Jul 17 2011 I've just begun updating my code to work with 2.054 and noticed that
- Dmitry Olshansky (13/50) Jul 17 2011 DirIterator is a range as of 2.054. And as being responsible for this
- KennyTM~ (19/21) Jul 17 2011 This compiles and runs for me:
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.
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.
--
Robert
http://octarineparrot.com/
Jul 17 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
Jul 17 2011
On Jul 17, 11 23:28, Robert Clipsham wrote:Also note that you can't use dirEntries() ~ dirEntries() or chain(dirEntries(), dirEntries()) as DirIterator is not a range.This compiles and runs for me: ----------------------------------- import std.file, std.range, std.algorithm, std.stdio; void main() { auto dFiles = filter!`endsWith(a.name, ".d")`(dirEntries(".", SpanMode.depth)); auto cFiles = filter!`endsWith(a.name, ".c")`(dirEntries("./foo", SpanMode.depth)); foreach (file; chain(dFiles, cFiles)) { writeln(file.name); } } ----------------------------------- The problem is *not* DirIterator not being a range, but that DirIterator is not a range of *string*. The foreach loop you're using foreach (string file; obj) { ... } requires an *opApply* which outputs strings from 'obj', but the range interface of 'DirIterator' outputs 'DirEntry'.
Jul 17 2011









Dmitry Olshansky <dmitry.olsh gmail.com> 