So... add maxCount and maxPos?

default0 via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 21 04:17:26 PST 2016


On Thursday, 21 January 2016 at 02:36:05 UTC, Ivan Kazmenko wrote:
> An alternative would be to define min(one argument) to just be 
> that argument.  That would be consistent with what we have now, 
> but violates the principle of least astonishment for newcomers: 
> why would min ([3, 1, 2]) return [3, 1, 2] and not 1?  
> Currently, it just does not compile.

As a newcomer to the language, and as a reader of 
https://dlang.org/phobos/std_algorithm_comparison.html#min which 
states "Iterates the passed arguments and returns the minimum 
value." my intuitive understanding would be that yes of course 
min(x) returns x.
However the above could of course also be reworded as "Iterates 
the passed list of arguments and returns the minimum value." to 
be even more clear about it NOT iterating individual arguments 
but the argument list as a whole :-)

If I were to be a newcomer to programming in general this might 
be confusing, though. However, it's certainly consistent and easy 
to wrap your head around and also what I would have expected it 
to do the first time I came across the function.



More information about the Digitalmars-d mailing list