let a = f64::min(foo(), bar());
let b = f64::min(foo(), bar());
Here, the meaning is extremely clear. Take the minimum (or maximum) of the value returned by foo()
and bar()
.
However, when using the postfix notation, I find it much harder to read:
let value = foo()
.min(bar())
.max(baz());
Instinctively, I try to read it as:
Compute
foo()
. The value will then be at minimum the value ofbar()
, and at maximum the value ofbaz()
.
If this seems right, re-read it, it's completely backward. The maximum is the value of bar()
and the minimum is the value of baz()
.
Am I the only one in this case?
This is very minor, so I don't feel that it would be justify to introduce two new functions at_most()
and at_least()
. I'm relatively sure that such change is breaking, so it could only be done at an edition barrier (which increase the bar even more). But I still think it would make the code much less prone to be miss-read.
let value = foo()
.at_most(bar())
.at_least(baz());