[RFC] Add an operator for ranges to D. Pros and cons?

Jonathan M Davis jmdavisProg at gmx.com
Wed Nov 7 11:14:14 PST 2012


On Wednesday, November 07, 2012 14:07:12 Dejan Lekic wrote:
> Therefore I would like to know what do you think about the idea
> of having additional operator exclusively made for ranges? This
> operator would make it obvious that data are "streamed" (lack of
> better term) among ranges.

As far as I can tell, it adds zero functionality. It's purely a matter of 
trying to create cleaner looking code. That being the case, I would think that 
suggestions like

auto something = inRange
 .fooRange(param)
 .barRange()
 .bazRange(param1, param2)
 .outRange();

solve the problem quite nicely, though I honestly, I have no problem with 
simply doing

auto something = outRange(bazRange(barRange(fooRange(inRange, param)), param1, 
param2));

though with that many chained items and several of them taking multiple 
parameters, something like

auto tempSomething = barRange(fooRange(inRange, param));
auto something = outRange(bazRange(tempSomething, param1, param2));

would probably be better. The first approach using UFCS seems rather popular 
though, and it's _very_ clean. My main gripe with it is that the flow is 
backwards, but I seem to be in the minority in thinking that.

Regardless, there are ways to format code so that it's quite clean without 
making any language changes. I don't see how adding an operator would really 
help. It just complicates the language further.

- Jonathan M Davis


More information about the Digitalmars-d mailing list