-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rename {super,sub} set methods to clearly indicate relation of operands #10020
Comments
Bang methods apply to the receiver. a.includes?(b) means "does a include b"? So a.subset?(b) naturally means "is a a subset of b?". So I don't this needs to change. That said, adding the "of" suffix makes it a bit more readable. |
I don't follow how you see a relation to bang methods. This is not about question mark representing nilable methods. Even if there is one, it's not obvious, which supports the argument that the API should be more explicit. These are all predicate methods. And as such, either way to read the relation between receiver and arg is possible. And as I mentioned above, I intuitively read |
Oh, sorry, I meant "question method".
That's the thing. Whenever there's A question method is always asking "Are you ...?" or "Do you ...?". It never asks something about the argument. That said, I think the "of" suffix makes this a bit clearer. |
I just realized that methods like
Set#subset?
apply in exactly the opposite direction to what I might expect.I would probably read a predicate method
subset?(b)
as "isb
a subset? (of the receiver)", i.e.b ⊂ a
But insteada.subset?(b)
returns true ifa ⊂ b
.These semantics are the same as in Ruby. I suspect they have it that way to have the same operand relation as with the comparison operators. But it's really confusing. When reading the code, you can't beyond doubt recognize which way it is.
So I'm proposing to rename these methods to a differnt, less ambiguous name. Adding a simple
_of
suffix would fix this.a.subset_of?(b)
clearly meansa ⊂ b
.Set#subset?
=>Set#subset_of?
Set#proper_subset?
=>Set#Proper_subset_of?
Set#superset?
=>Set#superset_of?
Set#proper_superset?
=>Set#proper_superset_of?
This also affects proposed similar methods for
Hash
(see #7500 (comment))The text was updated successfully, but these errors were encountered: