Order of arguments for std.range.take

Jonathan M Davis jmdavisProg at gmx.com
Mon Aug 15 22:00:58 PDT 2011


Okay. Currently take's arguments are range then number. As I understand it, 
they were previously number and then range, but some folks complained about 
not being able to use arrays' member function call syntax that way, so it was 
changed to what it is now. The downside to that is that code becomes much 
harder to read when you chain functions. e.g.

auto r = find(take(map!(std.uni.toUpper)(range), 5)), "hello");

is harder to read than

auto r = find(take(5, map!(std.uni.toUpper)(range))), "hello");

And of course, it only gets worse the more functions you chain. It becomes 
very easy to lose which function the number actually goes with. So, what I'm 
wondering is whether it would be worthwhile defining take _both_ ways.

Take!R take(R)(R input, size_t n)

and

Take!R take(R)(size_t n, R input)

Normally, I wouldn't want to do that, since it's arguably pointless function 
duplication, but it would be totally unambiguous in this case, and it would 
allow you to have the member function call syntax if prefer that or to have 
the increased readibility if you want that. I _really_ prefer having the size 
first, because it makes the code more readible, so personally, I'd prefer to 
either change it back to the way that it was or do this, but I can understand 
people wanting to use the member function call syntax for arrays.

So, the question is whether this is at all a good idea. And if not, is there 
any kind of real support for changing it back to take the number first? If 
we're stuck with the way that it is, we're stuck with the way that it is, but 
IMHO the current situation with take is suboptimal.

- Jonathan M Davis


More information about the Digitalmars-d mailing list