On Thursday, September 15, 2011 03:41 bearophile wrote:
> Christophe:
> > > What is "unuseful and confusing" about:
> > > 
> > > max!"a.length"(range); ?
> > 
> > What is confusing is that I don't know if this function returns a
> > length, or one of the elements of the range.
> 
> In Python the max and min work this way, and the students I have taught
> Python don't see this as a problem. On the opposite, they are thankful for
> this feature.
> 
> > It seems
> > (to me) more natural to give it a predicate to compare elements two at a
> > time. This is what is used in c++ std lib.
> 
> It's less natural. And D is not C++, there are more than just C++
> programmers in D. And it leads to longer & more complex code.

I think that that's up for debate. I would fully expect a min/max function to 
be using a comparator function, which means using a binary predicate. Also, 
given that everything else in std.algorithm which takes a predicate is taking 
an actually predicate and not what should be compared, having max take 
something like "a.length" would be extremely bizarre. I don't find 
max!"a.length"(range) to be natural at all. Maybe it's more natural for 
someone with little to no programming experience, but I really don't think 
that your average programmer is going to find it more natural.

- Jonathan M Davis

Reply via email to