Feature #5555
closedrename #include? to #includes?
Added by alexeymuranov (Alexey Muranov) about 14 years ago. Updated almost 9 years ago.
Description
Shouldn't the #include? method be renamed to #includes? ?
I think this will be closer to correct English and consistent with #has_key? method (not #have_key?).
Updated by shevegen (Robert A. Heiler) about 14 years ago
Actions
#1
[ruby-core:40686]
I am neutral on it, not pro, not con. But I think a simple alias could suffice here?
It is often a quite general question on english grammar too.
For instance, on class String I was using #starts_with? rather than #start_with?
But I think both should be equivalent.
"foo".starts_with? 'f' # => true
"foo".start_with? 'f' # => true
Updated by now (Nikolai Weibull) about 14 years ago
Actions
#2
[ruby-core:40698]
On Thu, Nov 3, 2011 at 00:00, markus heiler shevegen@gmail.com wrote:
Shouldn't the #include? method be renamed to #includes? ?
I think this will be closer to correct English and consistent with #has_key? method (not #have_key?).
One needs both for every case to be covered.
Updated by alexeymuranov (Alexey Muranov) about 14 years ago
Actions
#3
[ruby-core:40700]
Alias would be good enough for me. Thanks for comments.
Updated by agrimm (Andrew Grimm) about 14 years ago
Actions
#4
[ruby-core:40966]
The spelling chosen was deliberate, according to this 2001 email http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18951
"responds_to?" probably makes more sense to English speakers than
"respond_to?".Maybe. But I'm Japanese. Ruby is not English. It's the basic naming
rule to avoid third person singular form in the standard libraries.you = Human.new
if you.respond_to?(:knock)
...
endbuddies = member.collect{|x| x.friend_of?(me)}
buddies.respond_to?(:select)
Such spelling also exists for many other methods, such as String#start_with?
If the spelling of include? were to be aliased, I'd recommend aliasing the spelling of all such methods, such as start_with? . Failing to do so would be a far greater inconsistency than include? versus has_key?
Updated by wycats (Yehuda Katz) about 14 years ago
Actions
#5
[ruby-core:40969]
I'm personally willing to accept the "no third person singular" rule at
this point, given the history.
Yehuda Katz
(ph) 718.877.1325
On Sat, Nov 12, 2011 at 4:14 AM, Andrew Grimm andrew.j.grimm@gmail.comwrote:
Issue #5555 has been updated by Andrew Grimm.
The spelling chosen was deliberate, according to this 2001 email
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18951"responds_to?" probably makes more sense to English speakers than
"respond_to?".Maybe. But I'm Japanese. Ruby is not English. It's the basic naming
rule to avoid third person singular form in the standard libraries.you = Human.new
if you.respond_to?(:knock)
...
endbuddies = member.collect{|x| x.friend_of?(me)}
buddies.respond_to?(:select)Such spelling also exists for many other methods, such as
String#start_with?If the spelling of include? were to be aliased, I'd recommend aliasing the
spelling of all such methods, such as start_with? . Failing to do so would
be a far greater inconsistency than include? versus has_key?¶Feature #5555: rename #include? to #includes?
http://redmine.ruby-lang.org/issues/5555Author: Alexey Muranov
Status: Open
Priority: Normal
Assignee:
Category:
Target version:Shouldn't the #include? method be renamed to #includes? ?
I think this will be closer to correct English and consistent with
#has_key? method (not #have_key?).
Updated by Anonymous about 14 years ago
Actions
#6
[ruby-core:40970]
I agree.
Michel Demazure (French)
De : Yehuda Katz [mailto:wycats@gmail.com]
Envoyé : samedi 12 novembre 2011 16:17
À : ruby-core@ruby-lang.org
Objet : [ruby-core:40969] Re: [ruby-trunk - Feature #5555] rename #include?
to #includes?
I'm personally willing to accept the "no third person singular" rule at this
point, given the history.
Yehuda Katz
(ph) 718.877.1325
On Sat, Nov 12, 2011 at 4:14 AM, Andrew Grimm andrew.j.grimm@gmail.com
wrote:
Issue #5555 has been updated by Andrew Grimm.
The spelling chosen was deliberate, according to this 2001 email
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18951
"responds_to?" probably makes more sense to English speakers than
"respond_to?".Maybe. But I'm Japanese. Ruby is not English. It's the basic naming
rule to avoid third person singular form in the standard libraries.you = Human.new
if you.respond_to?(:knock)
...
endbuddies = member.collect{|x| x.friend_of?(me)}
buddies.respond_to?(:select)
Such spelling also exists for many other methods, such as String#start_with?
If the spelling of include? were to be aliased, I'd recommend aliasing the
spelling of all such methods, such as start_with? . Failing to do so would
be a far greater inconsistency than include? versus has_key?
Feature #5555: rename #include? to #includes?
http://redmine.ruby-lang.org/issues/5555
Author: Alexey Muranov
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
Shouldn't the #include? method be renamed to #includes? ?
I think this will be closer to correct English and consistent with #has_key?
method (not #have_key?).
Updated by Anonymous about 14 years ago
Actions
#7
[ruby-core:40974]
Feature #5555: rename #include? to #includes?
My personal preferences is #includes? but none of the std lib seems to match it.
I'd be all for a std lib include like
require 'english_grammar'
that creates the proper aliases :)
Updated by alexeymuranov (Alexey Muranov) about 14 years ago
Actions
#8
[ruby-core:40980]
Andrew Grimm wrote:
The spelling chosen was deliberate, according to this 2001 email http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/18951
"responds_to?" probably makes more sense to English speakers than
"respond_to?".Maybe. But I'm Japanese. Ruby is not English. It's the basic naming
rule to avoid third person singular form in the standard libraries.you = Human.new
if you.respond_to?(:knock)
...
endbuddies = member.collect{|x| x.friend_of?(me)}
buddies.respond_to?(:select)Such spelling also exists for many other methods, such as String#start_with?
If the spelling of include? were to be aliased, I'd recommend aliasing the spelling of all such methods, such as start_with? .
Failing to do so would be a far greater inconsistency than include? versus has_key?
Good explanation. The method names can also be read as #(does_it_)include?
However, #has_key? then needs to be renamed to or aliased as #have_key?.
I also like the anonymous suggestion to require 'english_grammar' :).
Updated by mame (Yusuke Endoh) over 13 years ago
Actions
#9
[ruby-core:43739]
- Status changed from Open to Feedback
- Assignee set to matz (Yukihiro Matsumoto)
- Priority changed from Normal to 3
Hello,
2011/11/13 Alexey Muranov muranov@math.univ-toulouse.fr:
Good explanation. The method names can also me viewed as #(does_it_)include?
I'm not sure but the rule seems Lisp's name convention?
Maybe it also came from Lisp (has-key-p).
However, #has_key? then needs to be renamed to or aliased as #have_key?.
Unak-san told me that there is another example: #is_a?.
I guess is_* and has_* are just two exceptions; they are accepted
idiomatic expressions. Do you really want #have_key? and #be_a?
I also like the anonymous suggestion to require 'english_grammar' :).
You can start by yourself with gem :-)
--
Yusuke Endoh mame@tsg.ne.jp
Updated by matz (Yukihiro Matsumoto) over 13 years ago
Actions
#10
[ruby-core:43765]
- Status changed from Feedback to Rejected
The basic naming for methods in standard class libraries are:
- use basic form (include not includes)
- put question mark for predicates
- put bang mark for "dangerous" version of methods
"is_a" and "has_key" are exceptions. "is_a" (or "isa") used very often for inheritance in OO context.
"has_key" has already been deprecated by "key?"
Besides that, backward incompatibility introduced by renaming them would be unbearable.
Matz.
Updated by alexeymuranov (Alexey Muranov) over 13 years ago
Actions
#11
[ruby-core:44272]
Thanks for the explanation, i didn't know about "key?".
Updated by Anonymous over 13 years ago
Actions
#12
[ruby-core:44592]
The basic naming for methods in standard class libraries are:
- use basic form (include not includes)
- put question mark for predicates
- put bang mark for "dangerous" version of methods
Speaking of which, could we get an Array#shift!
It always confuses me how that one defies the rule.
K thanks bye.
-roger-
Updated by now (Nikolai Weibull) over 13 years ago
Actions
#13
[ruby-core:44602]
On Tue, Apr 24, 2012 at 15:47, Roger Pack rogerdpack2@gmail.com wrote:
The basic naming for methods in standard class libraries are:
- use basic form (include not includes)
- put question mark for predicates
- put bang mark for "dangerous" version of methods
Speaking of which, could we get an Array#shift!
It always confuses me how that one defies the rule.
There’s no non-dangerous version of Array#shift, so it doesn’t defy the rules.
Updated by Anonymous over 13 years ago
Actions
#14
[ruby-core:44603]
It always confuses me how that one defies the rule.
There’s no non-dangerous version of Array#shift, so it doesn’t defy the rules.
True, I just always reach for shift! since it makes more sense in my head.
-r
Updated by cout (Paul Brannan) over 13 years ago
Actions
#15
[ruby-core:44605]
On Wed, 2012-04-25 at 05:24 +0900, Roger Pack wrote:
It always confuses me how that one defies the rule.
There’s no non-dangerous version of Array#shift, so it doesn’t defy the rules.
True, I just always reach for shift! since it makes more sense in my head.
-r
Do you try to call pop! as well? :)
Paul
Updated by Anonymous over 13 years ago
Actions
#16
[ruby-core:44607]
Do you try to call pop! as well? :)
That sounds like a balloon! yes! pop!
(I suppose in answer to your question, for some reason I don't use
pop, but I would probably reach for a pop! :)
Updated by astrokitty (Steve Bachmair) almost 9 years ago
Actions
#17
[ruby-core:79480]
The include?, start_with?, etc. issue is one of my very few gripes about this most beautiful of all languages. Is this the last word on this?
I'm puzzled at the the no third-person-singular naming convention, since 90% of my variables are in the third-person singular. I've never once used a variable called "you", nor have I ever written code that looks like does_it.include? What I have written is a million lines of code like if string.start_with? char and if object.respond_to? method, which would read a lot better as string.starts_with? char and object.responds_to? method.
I can't see how I would ever want start_with?, end_with?, respond_to?, etc. in the second person; every time I've ever used these I've called them on a third-person-singular variable. The only real case I see for non-third-person-singular would be third-person-plural (which happens to be the same a second person) on collections:
things = []
if things.include? thing
list_of_things = []
if list_of_things.includes? thing
Obviously, actually changing the method names is a non-starter for compatibility reasons, but I see no downside to aliasing new third-person singular forms to their second-person equivalents. Then we could just write whatever is most readable in a given circumstance (which will usually be the third-person form). If there's really no chance at this change I might take a stab at the english_grammar gem, but I think it'd be a lot better in the language itself.
Updated by stomar (Marcus Stollsteimer) almost 9 years ago
Actions
#18
[ruby-core:79482]
Steve Bachmair wrote:
Then we could just write whatever is most readable in a given circumstance (which will usually be the third-person form).
I just wanted to point out that "usual" depends: I almost always use names in pluralized form for arrays or hashes, like files, users, options, ..., instead of list, my_hash, or similar. And colors.includes? reads at least as bad as line.start_with?. (So, renaming those methods - which is what this issue is about - would not really help).
Updated by shyouhei (Shyouhei Urabe) almost 9 years ago
Actions
#19
[ruby-core:79483]
Please stop beating this dead horse.