is icon indicating copy to clipboard operation
is copied to clipboard

Proposal: is.Less and is.Greater

Open jftuga opened this issue 3 years ago • 1 comments

Would you consider adding these functions to the API? I could see it being useful for numeric comparisons but also understand that you want to keep the API to a minimum.

Thanks.

jftuga avatar May 01 '21 14:05 jftuga

imho is.True(..) already covers this and more..

wliao008 avatar May 10 '21 17:05 wliao008

I think this would compromise the ergonomics of the library by imposing ordering that you'd need to look at the arguments to know. The only two-argument method currently in the package is Equals(), which, conveniently, does not depend on ordering. Everything else breaks down to a simple boolean clause. The only reason Equals() even exists is because you need to guard against nil comparisons and also do some reflection to cover the most common sort of testing questions. Otherwise you could just do is.True(a==b)

What reads better?

is.True(a < b) // just boolean clauses
is.True(a>b)

or

is.Less(a, b) // which is the one that should be less?
is.Greater(b,a)
// or is it
is.Greater(a,b)
// I guess it depends on the language you speak!

You'd have to read the code to know for sure, since it no longer reads naturally. This is kind of a unique package in that the package name is part of the reading, which makes it feel light and readable, but also constrains the identifiers in expressions (IMHO for the better).

flowchartsman avatar Feb 24 '23 20:02 flowchartsman