An immediate example that comes to mind is Python's use of None, rather than null (like in Java/JavaScript). I remember speaking in Dutch about Java in college was always slightly awkward, because it was easy to confuse "null" with 0 (or "nul"). I wonder if Guido (being Dutch) called the Python void type "None" on purpose, to avoid awkwardness when speaking about it in Dutch.
An 'in' operator for Ruby
51–60 of 69 posts
Re: An 'in' operator for Ruby
#52Earlier quoted context omitted.
It's a side effect of their implementation and you should continue to not trust their default ordering.
It appears that since Ruby 1.9 they guarantee insertion order: http://ruby-doc.org/core-2.3.0/Hash.html I guess there are two approaches to solving the problem of people using your data structures the wrong way. Edit: wrong link
> When iterating over a map with a range loop, the iteration order is not specified and is not guaranteed to be the same from one iteration to the next. Since Go 1 the runtime randomizes map iteration order, as programmers relied on the stable iteration order of the previous implementation.
Re: An 'in' operator for Ruby
#53I actually found it more interesting that Ruby hashmaps ("hashes" :S) preserve insertion order and guarantee predictable insertion. I 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 becom…
It's a side effect of their implementation and you should continue to not trust their default ordering.
The implementation of a ruby hash is now as a doubly linked list [0]. This has inevitably caused a slight performance hit, but the benefits far outweigh the cost IMO.
[0] https://www.igvita.com/2009/02/04/ruby-19-internals-ordered-...
Re: An 'in' operator for Ruby
#54This would go against the ruby style of using predicates for this sort of thing (think `include?`, `empty?`, `nil?`). I personally wouldn't be in favor of it. Addition: Arguing that "Ruby isn't English" and then stating conformity to mathematical notation as a benefit seems hypocritical. Programming languages (besides APL, maybe) do not use strict mathematical notation, and we shouldn't want them to.
I do disagree with the author on one point: 'not in' should also be a valid operator, representing '∉'.
But I don't use Ruby; I mostly use Python, which has these operators.
Re: An 'in' operator for Ruby
#55Rails implements this as `in?` https://github.com/rails/rails/blob/d61baee52adcd1baebe15f10... You're welcome to try and merge that into Ruby core itself. That said, "I like whitespace" isn't a good reason to add a new operator over a method. Ruby is object oriented, meaning you are calling methods on objects.
He addresses this in his post. if x.in? my_set # very ugly With that said, I personally don't agree with the post.
I wouldn't call the method "in?" but maybe "element_of?" or "member_of?" but besides that, I don't see the need for an operator.
Re: An 'in' operator for Ruby
#56so.. is 10 'in' 10..100? is 100?
[1] pry(main)> 10..100
=> 10..100
[2] pry(main)> (10..100).class
=> Range
[3] pry(main)> (10..100).to_a
=> [10, 11, 12, 13, 14, ..., 99, 100]Re: An 'in' operator for Ruby
#57Earlier quoted context omitted.
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 :).
You should be happy, as Python 3 would have renamed it to "Ekke Ekke Ekke Ekke Ptang Zoo Boing!" 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.
Really '!=' is just an attempt at rendering '≠' using only ASCII characters. They're a bit like digraphs and trigraphs in C/C++, except everyone is used to them.
I wonder if Unicode is ubiquitous enough now that you could write a language where the real maths operators were used instead. What would that look like?
Re: An 'in' operator for Ruby
#58This would go against the ruby style of using predicates for this sort of thing (think `include?`, `empty?`, `nil?`). I personally wouldn't be in favor of it. Addition: Arguing that "Ruby isn't English" and then stating conformity to mathematical notation as a benefit seems hypocritical. Programming languages (besides APL, maybe) do not use strict mathematical notation, and we shouldn't want them to.
.include? isn't really a predicate, as predicates are typically unary. Rather, it's the 'member of' relational operator written in the wrong direction. Since we don't have '∈' in ascii, the author is proposing using the word 'in' instead. I do disagree with the author on one point: 'not in' should also be a valid operator, representing '∉'. But I don't use Ruby; I mostly use Python, which has these operators.
I can't think of any modern programming language that isn't unicode aware even though for the standard library methods, there are very good reasons not to use them (I know, Perl 6 does but even in this case there are ASCII fallbacks).
You should also have very good reasons to put methods on the root class of your class hierarchy.
Re: An 'in' operator for Ruby
#59if x.in? my_set # very ugly I guess we disagree there. This is arguably more readable than most languages with `in?` being still just a method.
I agree, I quite like it as a method as it keeps its congruence with .include? as an opposite of .in? (what .in? does should have been what .include? did from the get go). Perhaps another way of doing this is calling the method .within?
Re: An 'in' operator for Ruby
#60Earlier quoted context omitted.
.include? isn't really a predicate, as predicates are typically unary. Rather, it's the 'member of' relational operator written in the wrong direction. Since we don't have '∈' in ascii, the author is proposing using the word 'in' instead. I do disagree with the author on one point: 'not in' should also be a valid operator, representing '∉'. But I don't use Ruby; I mostly use Python, which has these operators.
It's not a problem using non ASCII method names in Ruby: https://gist.github.com/bhaak/91428b9aee88ac50dd1d I can't think of any modern programming language that isn't unicode aware even though for the standard library methods, there are very good reasons not to use them (I know, Perl 6 does but even in this case there are ASCII fallbacks). You should also have very good reasons to put methods on the root class of yo…
Making it easy for people to type them, on the other hand...