std.range: Order of arguments unluckily chosen?

Timon Gehr timon.gehr at gmx.ch
Mon Jun 6 09:34:36 PDT 2011


so wrote:
> Nice idea to make sense out of the UFCS, but i fail to realize the
> actually need for UFCS to begin with.
> To me, the need to convert "take(3, range)" to "range.take(3)" is
> non-existent (and this wouldn't be the only reason i could come up with),
> probably i am missing something. And because everyone likes this, it must
> be something big :)

I think it is about readability of nested statements:

take(10,stride(2,cycle([3,2,5,3])));

vs.

[3,2,5,3].cycle().stride(2).take(10);

The first one is: "Take 10 of every 2nd element of cyclic [3,2,5,3,...].
The second one is: "Start with [3,2,5,3]. Then cycle that. Then only look at every
2nd element of that. Finally, take 10 elements out of the resulting range."

The second version writes the actions in the order they are performed, while the
functional way is more like what you'd get if you had to describe the entire
process in a single sentence. It also reduces nesting of parentheses. I am fine
with both. But I dislike

take(stride(cycle([3,2,5,3]),2),10);


Timon



More information about the Digitalmars-d mailing list