Take out Object#among? but add in Object#ex? - #265
Conversation
|
-1 for Object#ex? Not only does 'ex' mean "out of," it also means "from" and implies that it was once in the list. ex-pirate = Once a pirate, but no longer a pirate. option.ex?(:foo, :bar) # Was once :foo or :bar, but no longer is? There's too much linguistic baggage to be repurposed this way. |
|
+1 on removing I'm also with @phene on -1 for |
|
I suggest using another Latin word: "sans". It was suggested in the previous pull request and I think it's worth reconsidering. 1) It's short 2) It's precise 3) The community knows what it means - e.g. sans-serif means a font without serifs. |
|
Object#in? is nice, and adds expressivity. As for the rest of them, I made the comment on #258, but I think it remains relevant to the discussion on #ex?: This discussion is like TDD for syntax, and I think the tests are telling us something. in? Feels pretty natural, and is handy in the same way blank? and present? are. All of the rest just feel wrong. I think this is because we're trying to solve a nonexistent problem. Someone mentioned earlier how the English language doesn't really have clear one-word negation options here. That's because in English, we would say "3 is not in the set of 1, 2, 4". I think this tells us something, given that only real use for this method is in conditionals, to begin with (including the ternary operator). The rest aren't needed. Where we ask "if object.in?(array)", the opposite is "unless object.in?(array)". If necessary, !object.in?(array) feels pretty natural as well. This seems obvious, as we discuss this. blank? was handy given ruby's definition of truthiness, but present? was a welcome addition because negating a "negative" (!blank?) method like blank was often less expressive of intent. You don't ask "is that space still blank?" as often as you ask "has it been filled in?" Since the English idiom here is to say "not in", I think the standard Ruby idioms for negating the condition already complement in? nicely. |
|
I like sans, but the object-subject order doesn't fit for this scenario.
makes a lot more sense than
|
|
I don't understand why are we jumping through so many hoops to avoid using "not in"? Is it really that bad? Is it really so bad that we have to leave the English language entirely to find an alternative?! I know some people find it ugly, but to me, it reads exactly as it should work. With most of the other suggestions, I have do a small mental conversion back to "not in". It's also the most obvious - I wouldn't need to bother looking up documentation if I ever came across this code in use. not_in? just seems more self documenting, just like exclude?, present?, etc. ex? and sans? are not so obvious without the help of an explanation or documentation to justify their use. The only caveat, which I somewhat agree with, is that we already have the negation operators '!' and 'not' that already does this. But like much of ruby (and rails) there's more than one way to skin a cat. |
|
This is my proposal for
So in some context which you test against two items, you might consider For I'm neither tenderlove, DHH, nor josevalim. |
|
+1 for removing or |
|
Seeing ex? in usage here, I'm falling out of favor too. Let's just start small, we don't need to solve everything now. The big win is just to get Object#in? -- we can think deeper about the perfect opposite some other time. @sikachu, please rebase one last time with only Object#in? being part of the game and we'll move on from this for now. |
|
Will do. Sent from my iPhone On 13 เม.ย. 2554, at 16:11, [email protected] wrote:
|
|
The pull request has been updated with one commit only. |
After a long list of discussion about the performance problem from using varargs and the reason that we can't find a great pair for it, it would be best to remove support for it for now. It will come back if we can find a good pair for it. For now, Bon Voyage, `#among?`.
|
This pull request has been merged and shall now be closed. |
After a very long discussion on #258 and discussion with @dhh, we've decide that we want to do two things to it.
1. Remove
Object#among?The reason for removal would be because these three things:
obj.in?([1,2,3])is wayyyyy shorter thanobj.among?(1,2,3)If you really want
obj.among?, please show us your support by saying so and suggest a good name for inverse of it.2. Add
Object#ex?A while ago, @pigoz has come up with this wonderful name from Latin. We think it fits with
#innicely, so we're including it here. You could say that "#ex? is the new #not_in?`Feedback needed!
Please keep the awesome discussion going. Make a comment if you like it/hate it.