max operates only on its arguments*, and is only useful if the number of args is > 1.** maximum operates on a collection and only takes a second argument in specific cases.
Is there any reason why we couldn’t have a single-argument method on max that, if given a collection, returns the equivalent of maximum?
*max has deprecated behavior in that it will operate on collections in an element-wise order.
**This is inconsistent: max(5) returns (the possibly-expected) 5, but max([1,2,3]) does not return [1,2,3], nor does max("a") return a.
The “inconsistency” is that some types are comparable and some are not.
I can understand that if you’re comparing two things. But what are you comparing with a single-argument max, and how is max(x::Real) = x useful?
And I swear it’s complete coincidence that I asked this question within 2 hours of @jeff.bezanson closing that issue out (I didn’t even know it existed).
The behavior of max("a") basically means that the current implementation is not consistent enough and should be fixed. It’s not an argument for making it even more inconsistent. The max([1, 2, 3]) case is irrelavent.
You could just add square brackets to the max argument in that case:
f(x...) = max([x...])+1
I would like to have just one function to get the maximum of a collection or several items.
The two functions always confuse me and i think that the dot-notation removes the ambiguities.
Is there any reason why we couldn’t have a single-argument method on max that, if given a collection, returns the equivalent of maximum?
There was a long discussion in #4235. It explained the logic. Personally, I think there is no simple and intuitive reason for not choosing an unified max method.
From what I understand from related discussion, the drawbacks for using a unified max method are:
(1) A single max with keyword arguments method is run-time slower than the max + maximum combination. So a performance-wise issue.
(2) A single max method breaks the consistency of dot-call usages. For example, the max would work for both max(scalar) and max(vector). Some developers argued that a single method accepts both scalar and vector input is confusing or redundant(use dot-call instead). Two other examples are sin and clamp, both of them do not accept vector input either.
IMHO, current implementation is explainable but not intuitive enough.