An 'in' operator for Ruby
31–40 of 69 posts
Re: An 'in' operator for Ruby
#32Re: An 'in' operator for Ruby
#33> if item not in collection # travesty! > if ! (item in collection) # ok Riiiiiiiight. No more language suggestions from you, thanks ;)
Agreed > if item not in collection reads quite nicely. I don't see what the problem is there? Anyway, I don't think his one gripe with this is enough reason to throw the rest of his argument out.
Obviously is the best choice
Re: An 'in' operator for Ruby
#34> if item not in collection # travesty! > if ! (item in collection) # ok Riiiiiiiight. No more language suggestions from you, thanks ;)
Agreed > if item not in collection reads quite nicely. I don't see what the problem is there? Anyway, I don't think his one gripe with this is enough reason to throw the rest of his argument out.
Re: An 'in' operator for Ruby
#35Earlier quoted context omitted.
Agreed > if item not in collection reads quite nicely. I don't see what the problem is there? Anyway, I don't think his one gripe with this is enough reason to throw the rest of his argument out.
unless item in collection Obviously is the best choice
Re: An 'in' operator for Ruby
#36If it's this importing why not propose it: https://bugs.ruby-lang.org/ Ruby has a place for this sort of thing and they'll answer you.
Re: An 'in' operator for Ruby
#37I was taught to never trust the ordering returned by iterating over keys of hashmaps because it can be a source of bugs as you move between architectures or interpreters. If you need a guaranteed ordering, keep (and pay for) the appropriate auxiliary data structure.
Has this lesson become obsolete? Perhaps "computers are fast" so now Ruby can afford to use ordered hashmaps everywhere. On the other hand, I know Go chose to randomize iteration order of keys on purpose so developers cannot rely on them.
Re: An 'in' operator for Ruby
#38I understand the perceived benefit of compositional eloquence that this may add (pretty much borrowing from Python) but as others have pointed out, this is incongruent to the design of Ruby as a language and how it treats the relation between objects and their methods. Additionally, you lose any compositional elegance you may have gained when you decided not to use: x not in y and instead propose: !(x in y) Seems lik…
I find `not in` highly dubious - it makes the expression grammar awkward and harder to parse. Is `not in` a two-token operator? Or is `not` an adverb in this context? What else resembles this? To cite an alternatice, in Tcl, `in` is an operator and its negation is `ni`. A cute pun and echo of Monty Python that I'm disappointed Python didn't follow :).
As to the "what else resembles this"? I would turn it around and ask what else could resemble this. I'm not sure the conclusion would be that "not in" is a good thing, but not sure of the reverse, either:
if x not = 3
looks weird, but I think I could grow to like it.Re: An 'in' operator for Ruby
#39> if item not in collection # travesty! > if ! (item in collection) # ok Riiiiiiiight. No more language suggestions from you, thanks ;)
he should have suggested
if not item in collection
which should then work out of the box anyways
[I completely agree with the need for the 'in' operator]
Re: An 'in' operator for Ruby
#40One of my favorite aspects of Ruby is that everything is an object with methods. Adding global operators/functions like this would only complicate the language. > But we also -- perhaps more often? -- ask questions like "Is this item part of this group?" We are asking a question about the item . Here we are actually asking the group a question about itself. An item would not know a group's contents.