std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

Paul Backus snarwin at gmail.com
Wed Jun 24 15:55:50 UTC 2020


On Wednesday, 24 June 2020 at 15:26:40 UTC, Stanislav Blinov 
wrote:
>
> Libraries shan't be for "beginners" nor "advanced users". And 
> that use case is already a non-beginner. Beginners would write 
> this:
>
> auto data = 
> createSomeInput(args).filter!somehow.map!something.array;
>
> Create input, consume input, with no explicit moves in sight. 
> Piecemeal consumption of an input range is something an 
> "advanced" user would be doing :)

Ok. Now they refactor their code:

auto input = createSomeInput(args);
auto data = input.filter!somehow.map!something.array;

Kaboom! Compile error. This is why Walter's proposal is relevant 
here.

> You're aware of a recent question in .learn there, where the 
> user attempted to iterate a non-copyable range (the thread 
> which turned into another prolonged discussion: 
> https://forum.dlang.org/post/kpncjzadrwpvxupsdmle@forum.dlang.org). A range which, by the way, was an input range. The explanations quickly went into "common pitfalls" territory. Jonathan M Davis' response was of particular interest: "In general, you should never use a range after it's been copied unless you know exactly what type of range you're dealing with and what its copying behavior is. If you want an independent copy, you need to use save."

To be clear: I agree with you *in principle* that pure input 
ranges should be non-copyable. It's just that currently, 
non-copyable types are rather cumbersome to work with in D, and 
IMO it would be a step backwards in terms of usability to force 
them on users of std.algorithm and std.range.

The solution is to make working with non-copyable types more 
ergonomic, and then make pure input ranges non-copyable.

This will also improve the signal-to-noise ratio of compile 
errors: with automatic move-on-last-use, when the compiler 
complains about copying a range, you can be sure you have 
actually made a mistake somewhere in your logic, rather than just 
forgetting to type ".move".


More information about the Digitalmars-d mailing list