Project

General

Profile

Actions

Feature #5555

closed

rename #include? to #includes?

Added by alexeymuranov (Alexey Muranov) about 13 years ago. Updated over 7 years ago.

Status:
Rejected
Target version:
-
[ruby-core:40684]

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 13 years ago

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 13 years ago

On Thu, Nov 3, 2011 at 00:00, markus heiler 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 13 years ago

Alias would be good enough for me. Thanks for comments.

Updated by agrimm (Andrew Grimm) almost 13 years ago

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)
...
end

buddies = 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) almost 13 years ago

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 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)
...
end

buddies = 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?).

--
http://redmine.ruby-lang.org

Updated by Anonymous almost 13 years ago

I agree.

Michel Demazure (French)

De : Yehuda Katz []
Envoyé : samedi 12 novembre 2011 16:17
À :
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
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)
...
end

buddies = 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?).

--
http://redmine.ruby-lang.org

Updated by Anonymous almost 13 years ago


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) almost 13 years ago

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)
...
end

buddies = 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 12 years ago

  • Status changed from Open to Feedback
  • Assignee set to matz (Yukihiro Matsumoto)
  • Priority changed from Normal to 3

Hello,

2011/11/13 Alexey Muranov :

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

Updated by matz (Yukihiro Matsumoto) over 12 years ago

  • 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 12 years ago

Thanks for the explanation, i didn't know about "key?".

Updated by Anonymous over 12 years ago

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 12 years ago

On Tue, Apr 24, 2012 at 15:47, Roger Pack 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 12 years ago

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 12 years ago

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 12 years ago

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) over 7 years ago

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) over 7 years ago

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) over 7 years ago

Please stop beating this dead horse.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0