to compose or hack?

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 7 13:09:07 UTC 2021


On 7/6/21 11:42 PM, Jon Degenhardt wrote:
> On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote:
>> This is pretty minimal, but does what I want it to do. Is it ready for 
>> inclusion in Phobos? Not by a longshot! A truly generic interleave 
>> would properly forward everything else that the range supports (like 
>> `length`, `save`, etc).
>>
>> But it got me thinking, how often do people roll their own vs. trying 
>> to compose using existing Phobos nuggets? I found this pretty 
>> satisfying, even if I didn't test it to death and maybe I use it only 
>> in one place. Do you find it difficult to use Phobos in a lot of 
>> situations to compose your specialized ranges?
> 
> I try to compose using existing Phobos facilities, but don't hesitate to 
> write my own ranges. The reasons are usually along the lines you describe.
> 
> For one, range creation is easy in D, consistent with the pro/con 
> tradeoffs described in the thread/talk [Iterator and Ranges: Comparing 
> C++ to D to 
> Rust](https://forum.dlang.org/thread/diexjstekiyzgxlicnts@forum.dlang.org). 
> Another is that if application/task specific logic is involved, it is 
> often simpler/faster to just incorporate it into the range rather than 
> figure out how to factor it out of the more general range. Especially if 
> the range is not going to be used much.

Yeah, I agree with all this. I do try to use existing ranges/algorithms 
as much as possible. But I find it awesome you can just whip up a quick 
shim range to get work done and not worry about making it perfect for 
general consumption. Kind of like a lambda range ;)

-Steve


More information about the Digitalmars-d-learn mailing list