-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R.propIs() and R.propEq() have inconsistent argument order #2428
Comments
It's a good question. I believe I remember waffling on the argument order for propIs(Number) ~~> name => obj => is(Number)(prop(name, obj))
propSatisfies(isOdd) ~~> name => obj => idOdd(prop(name, obj)) These seem so obviously right that I'm loathe to change them. propEq(42) ~~> name => obj => equals(42)(prop(name, obj)) we would certainly add some consistency. I think it would be worth hearing from others whether they think this consistency is worth breaking backward compatibility. What do you say @ramda/core? |
The order of The prop you are checking is the most static argument, the value to compare against is the second most static. Often the second value will be based on user input or database values but sometimes they are constants. And the object you compare against is almost always user input. For some function, argument order can be tricky. I really do not think this is in the case for |
The reverse seems equally likely in my experience: const uninitialized = flip(propEq)(null)
const noName = uninitialized('name')
noName({age: 10, name: null}) //=> true
That doesn't surprise me, although I don't recall it.
I think it's a worthy consideration if the order is not already dictated by other factors, which, of course, it usually will be. Consistency is quite useful. |
Really? I mean sure it can happen but is it as common as the other case? Do you have several props that you all want to check for a specific value? If we look at projects that use Ramda, do we find that |
For any function I would say that if it is flipped more often than it is not, that would be the only reason to change order. I mean, consider that you would need to do Consistency in the form of |
Often enough that I have many times had concerns about the ordering. I'm guessing that it's probably 3 : 2 in favor of the existing order in my own uses. (I guess I was exaggerating about "Equally likely".)
Absolutely. The only way this would come to be a major factor is if it was hovering somewhere close to 50%. |
I am surprised at your 3:2 ratio. I did a search in my company's code and found 242 cases of I have never used
|
I think the bigger point here is that there should be a consistency between naming and argument order ( What that order exactly is might be less important (since you can always flip it). Simply choosing the order based on the popularity of use cases per function might not be a good idea and detrimental to the overall consistency which is really important for a library with ~200 functions. Having the ability to flip or having flipped functions prepackaged (like having both |
I think that getting the order right in terms of ergonomics is much more important than basing the order on the function name.
For my part though I wouldn't change it, as I can't think of a time that I have flipped it, even though I use it fairly often. |
I think part of the reason I don't get frustrated with this one is that I most often partially apply the first two parameters. I don't do a lot with either @helios1138: While I'm sympathetic to your suggestion, I would never let the inter-function consistency overrule the ergonomics of individual functions. And while we strive for some consistency in the words used in function names (such as That one could just The only reason I wobble here a bit is that I'm not particularly convinced that So if we were to start from scratch, I might like a different name for |
R.propIs()
andR.propEq()
are named similarly enough that it's expected that they would place the prop name argument in the same placeR.propIs()
takes prop name as the last argument whileR.propEq()
takes it as the last oneR.propIs()
should reverse it's argument order or reverse its name to something likeR.isProp()
or vice versa for the other oneR.propEq()
takes two strings you can't quickly understand which of them is the prop name and which is the value unless the argument order is intuitively consistent with function names across the libraryR.propOr()
I guessThe text was updated successfully, but these errors were encountered: