String starts? and ends? methods

On Sep 27, 2006, at 9:05 AM, Jonas H. wrote:

further: could there be need for starts_with!() and ends_with!() ?
or is it bollox?

What functionality are you envisioning these methods would have?

James Edward G. II

Hi,

In message “Re: String starts? and ends? methods”
on Wed, 27 Sep 2006 23:05:44 +0900, Jonas H.
[email protected] writes:

|but what about puralization?

As a convention, Ruby method names use plain verb with singular form,
with several exceptions, e.g. is_a? etc. So we use start_with? not
starts_with?

						matz.

Yukihiro M. [email protected] wrote:

So we use start_with? not
starts_with?

is it start_with? (underscore) or startwith? ?

Une bévue wrote:

Yukihiro M. [email protected] wrote:

So we use start_with? not
starts_with?

is it start_with? (underscore) or startwith? ?
that has just been changed (see discussion last hours on this topic)
from without to with (so start_with)

James Edward G. II wrote:

On Sep 27, 2006, at 9:05 AM, Jonas H. wrote:

further: could there be need for starts_with!() and ends_with!() ? or
is it bollox?

What functionality are you envisioning these methods would have?

James Edward G. II

maybe without parameters exchanging the first or last char with a
string/char, with parameters (unsigned integer) exchanging the first x
chars / last x chars

i dont know if it is that useful, it just popped to my mind seeing a
method? what would method! do.

newbish regards
Jonas

[email protected] wrote:

It’s a little inconsistent:

obj.respond_to? # second person
obj.is_a? # third person

But I think second person is the most common. Or maybe are_a? just
sounded too weird :slight_smile:

As the other cases are using the infinitive form,
the latter would actually be #be_a? :slight_smile:

Hal

Yukihiro M. wrote:

I think this is reasonable (or maybe I am just used to it).

Those who want an English mnemonic can mentally insert
the word “does”:

 str.start_with?(foo)  #  Does str start with foo ?

Hal

Hi –

On Thu, 28 Sep 2006, Hal F. wrote:

As the other cases are using the infinitive form,
the latter would actually be #be_a? :slight_smile:

I think it’s the second person – at least, I seem to remember Matz
explaining it that way. So you’re asking the object: [do you]
respond_to?..

We could go old school:

obj.respondest_to?
obj.art_a?

:slight_smile:

David

On 28/09/2006, at 12:33 AM, Yukihiro M. wrote:

In message “Re: String starts? and ends? methods”
on Wed, 27 Sep 2006 23:05:44 +0900, Jonas H. <Mail@Jonas-
Hartmann.com> writes:

|but what about puralization?

As a convention, Ruby method names use plain verb with singular form,
with several exceptions, e.g. is_a? etc. So we use start_with? not
starts_with?

“Starts” is not the plural form of “start”, it’s just a conjugation.

I start/you start/he, she, it starts/we start/you start/they start

You would never say in English “a start with b”, you say “a starts
with b”, even when both a and b are singular. I would argue that it
should be the same in Ruby, and the method name should be “starts_with?”

Pete Y.

[email protected] wrote:

We could go old school:

obj.respondest_to?
obj.art_a?

:slight_smile:

Forsooth!

Hal

Hi –

On Thu, 28 Sep 2006, Pete Y. wrote:

with several exceptions, e.g. is_a? etc. So we use start_with? not
starts_with?

“Starts” is not the plural form of “start”, it’s just a conjugation.

I start/you start/he, she, it starts/we start/you start/they start

You would never say in English “a start with b”, you say “a starts with b”,
even when both a and b are singular. I would argue that it should be the same
in Ruby, and the method name should be “starts_with?”

I believe the rationale is that it’s in the second person: do you
start with … ? I realize Matz mentioned singular vs. plural, but I
think that was just shorthand for with/without an ‘s’. In the past,
if I remember correctly, he’s talked about it as a function of person.

David

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rimantas L. wrote:

Makes sense. It was just honoring the origin (this case Python).
Since they are young (I just added it last week), it is fairly easy to
change the names. Any opinion?

                                                    matz.

+1 for changing to start_with? end_with?

Consistency in naming is a big plus for ruby (and minus for PHP).

+1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFFGyk9mV9O7RYnKMcRAlwaAKCE8ydXuZC+Y+UWA0F4dbYOZV6+/gCfS9pw
Pg5WAPp0YDsnjE38Qb6akd0=
=inCH
-----END PGP SIGNATURE-----

On 28/09/2006, at 10:42 AM, [email protected] wrote:

You would never say in English “a start with b”, you say “a starts
with b”, even when both a and b are singular. I would argue that
it should be the same in Ruby, and the method name should be
“starts_with?”

I believe the rationale is that it’s in the second person: do you
start with … ? I realize Matz mentioned singular vs. plural, but I
think that was just shorthand for with/without an ‘s’. In the past,
if I remember correctly, he’s talked about it as a function of person.

For non-predicate methods, the second person makes sense. Take
String.squeeze for example…that’s really about you (the second
person) squeezing the string.

For predicate methods it still seems odd. In the “starts with” case,
it’s not you doing the starting; it’s the string (third person) doing
the starting.

The said, the convention in Ruby does seem to be second person no
matter what. Witness the “include?” method for example (which has
always felt a little odd to me too.)

Pete Y.

On 9/27/06, Pete Y. [email protected] wrote:

For non-predicate methods, the second person makes sense. Take
String.squeeze for example…that’s really about you (the second
person) squeezing the string.

Sorry for entering this thread now to give my two cents. I’m sorry
because I’m a Ruby newbie AND a non-native english speaker, but I
thought I should say this.

I don’t think the person is really the question here. I think it’s the
imperative form of the verb.
In that case, I have always interpreted that (both in english and in
my native language) as you telling the string to squeeze itself.
File.open, for example, reads like “Hey, File class, open this for me,
please”. I’m imperative, but polite :).

I think that’s why most methods which do not ask for something are
written like that. I’d also prefer the “starts_with?” name, but if
“start_with?” is more consistent, I say stay with that.

Cheers,
Alvim.

You would never say in English “a start with b”, you say “a starts
with b”, even when both a and b are singular. I would argue that it
should be the same in Ruby, and the method name should be “starts_with?”

Ruby: foo.start_with? ‘snark’
English: does foo start with ‘snark’?

I could possibly see your point for something like start_with! (should
it
ever exist), but I think the question form sounds correct.

  • James M.

On Sep 28, 2006, at 9:11 , [email protected] wrote:

sounded too weird :slight_smile:

As the other cases are using the infinitive form,
the latter would actually be #be_a? :slight_smile:

I think it’s the second person – at least, I seem to remember Matz
explaining it that way. So you’re asking the object: [do you]
respond_to?..

So it should be #are_a?, right?

Michael G.
grzm seespotcode net

On 9/27/06, Michael G. [email protected] wrote:

obj.respond_to? # second person

So it should be #are_a?, right?

Nah, is_a? which derives from

is you is? or is you ain’t

I too find that the second, instead of third person form for
predicates to we just a tad wierd.

But it is what it is.

Or maybe that should be (as a predicate).

are you what you are?

And let me say that Matz’ English is much better than my Japanese.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

fr David:

Yes: add the underscores. Otherwise we’ll have those exceptions "for

historical reasons" – in this case the history of Python! :slight_smile:

Hi David, nuby here. i just got hit by ::foreach. Why is it not
for_each?
kind regards -botp

David

On 28/09/2006, at 12:36 PM, Marcelo A. wrote:

imperative form of the verb.
In that case, I have always interpreted that (both in english and in
my native language) as you telling the string to squeeze itself.
File.open, for example, reads like “Hey, File class, open this for me,
please”. I’m imperative, but polite :).

I think you’re absolutely right Marcelo, and you’ve once again proved
that non-native English speakers tend to know way more about grammar
than native English speakers like me. :slight_smile:

Pete Y.

Marcelo A. wrote:

I don’t think the person is really the question here. I think it’s the
imperative form of the verb.
In that case, I have always interpreted that (both in english and in
my native language) as you telling the string to squeeze itself.
File.open, for example, reads like “Hey, File class, open this for me,
please”. I’m imperative, but polite :).

Interesting. Some methods are imperative in form. But the ones
that are interrogative take the form they do (IMO) because it’s
the infinitive form of the verb. (Of course, the imperative
usually uses the infinitive…)

I think that’s why most methods which do not ask for something are
written like that. I’d also prefer the “starts_with?” name, but if
“start_with?” is more consistent, I say stay with that.

We agree on that. Besides, after 13 years, this convention is not
likely to change.

Hal