Start_with? Does someone need a grammar lesson?

String#start_with?-------------------------------

 str.start_with?([prefix]+)   => true or false

 From Ruby 1.9.1

 Returns true if _str_ starts with the prefix given.

Whoever wrote the docs doesn’t:

Returns true if str starts with the prefix given. I find it so
jarring to read:

if mystring.start_with?(“bad grammar”)

I’m hesitant to use start_with?() in my code. It makes me look
uneducated. :frowning:

You can fix the English grammar in a number of ways. For example:

define a function does

does mystring.start_with?(“bad grammar”)

or, even worse, rename your variable

if my_characters.start_with?(“good grammar”) # i’m choosing
grammatical correctness by breaking the semantics

Remember, “A foolish consistency is the hobgoblin of little minds,
adored by little statesmen and philosophers and divines.”

English grammar is sufficiently arbitrary, and fluid, to be a poor
indicator of programming language quality.

Peter

7stud – wrote:

I’m hesitant to use start_with?() in my code. It makes me look
uneducated. :frowning:

Hmm…I guess start_with?'s name is consistent with the naming
“convention” used by some other ruby methods, such as respond_to.

On Mon, Aug 17, 2009 at 1:59 AM, 7stud –[email protected] wrote:

7stud – wrote:

I’m hesitant to use start_with?() in my code. It makes me look
uneducated. :frowning:

Hmm…I guess start_with?'s name is consistent with the naming
“convention” used by some other ruby methods, such as respond_to.

Yep, I too found it a bit jarring when I first started using Ruby,
but it has become one of those things you just accept, just like
accepting that if you’re speaking French must adjectives come after
nouns.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

On Mon, Aug 17, 2009 at 2:35 PM, Rick DeNatale[email protected]
wrote:

accepting that if you’re speaking French must adjectives come after
nouns.

I bet you prefer that I call you “vieux ami” instead of “ami vieux”
though!

But your observation is correct and can be extended to most latin
languages.

Cheers
Robert

I’m hesitant to use start_with?() in my code. It makes me look
uneducated. :frowning:

I’d be quite happy if someone came up with a gem that aliased
“correct” english method names to the existing :slight_smile:
-r

7stud – [email protected] writes:

if mystring.start_with?(“bad grammar”)

I’m hesitant to use start_with?() in my code. It makes me look
uneducated. :frowning:

mystring.start_with? (or include? or respond_to? and so on) are best
liked when read and understood as a question:

do you [mystring] start with “bad grammar”?

Dominik H. wrote:

do you [mystring] start with “bad grammar”?

Or

does mystring start with “bad grammar”?

maybe we should lobby to replace “if” with “does” :stuck_out_tongue:

2009/8/17 Robert D. [email protected]:

Yep, I too found it a bit jarring when I first started using Ruby,
but it has become one of those things you just accept, just like
accepting that if you’re speaking French must adjectives come after
nouns.

I bet you prefer that I call you “vieux ami” instead of “ami vieux” though!

Well, I committed a typo, that I realized right away, but was too
lazy? to correct.

I meant to say that in French most adjectives come after nouns.

In English the sentence, “Must adjectives come after nouns.” is
ungrammatical unless the period is changed to a question mark.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

On Tue, Aug 18, 2009 at 1:54 AM, Rick DeNatale[email protected]
wrote:

lazy? to correct.

I meant to say that in French most adjectives come after nouns.

In English the sentence, “Must adjectives come after nouns.” is
ungrammatical unless the period is changed to a question mark.

Now I am confused. But no, they do not need to stand after nouns,
often short ones stand in front.
E.g.
C’est une belle femme.
vs.
C’est une femme sympathique.
(same for Italian)
And in the example I gave the semantic changes.
Vieux ami --> Good old friend
Ami vieux --> Aged friend
(same for Italian, no wonder the French learn it so quickly)

But in general they do stand behind nouns. Are there not some examples
of adjectives after the noun in English too, poetry?

Cheers
Robert

On Mon, Aug 17, 2009 at 4:03 PM, Dominik H.[email protected]
wrote:

do you [mystring] start with “bad grammar”?

Nah, it’s a common artifact of moving east asian grammar to western.
Besides that, you shouldn’t try to reinvent by changing the wheel.
People obviously think that proper would be “a single object” “starts
with”. But if you think of that simple object for what it is, a bunch
of bytes, than the discrepancy goes away. It’s plural vs. singular.
Don’t really care.

Todd

Think of it as a question in second-person. As:

Hey str, do you start_with “hello” ?

cheers
nilesh
http://nileshtrivedi.in

On Tue, Aug 18, 2009 at 8:05 PM, Todd B.[email protected] wrote:

Nah, it’s a common artifact of moving east asian grammar to western.
Besides that, you shouldn’t try to reinvent by changing the wheel.
People obviously think that proper would be “a single object” “starts
with”. But if you think of that simple object for what it is, a bunch
of bytes, than the discrepancy goes away. It’s plural vs. singular.
Don’t really care.

I didn’t give an example. My bad…

things_that_are_important_to_me starts with “start”

Todd

Todd B. [email protected] writes:

things_that_are_important_to_me starts with “start”

Todd

I honestly rather like to explain this “artifact” by the fact what it
is. A message sent to a receiver. You ask a receiver about its state,
not the world around it. So “do you” actually makes more sense than
asian/western grammar as an explanation, imho.

On Thu, Aug 20, 2009 at 8:54 AM, Dominik H.[email protected]
wrote:

I didn’t give an example. My bad…

things_that_are_important_to_me starts with “start”

Todd

I honestly rather like to explain this “artifact” by the fact what it
is. A message sent to a receiver. You ask a receiver about its state,
not the world around it. So “do you” actually makes more sense than
asian/western grammar as an explanation, imho.

You might be right. But in any case, I’m guessing at least 40% of
programmers use plurals instead of collective nouns (i.e. lions
instead of pride) – especially in databases (90% plural morbidity
there) – then the use of start_with makes perfect sense. Whether it
really is a spoken language artifact or not is irrelevant, I guess, so
I apologize for bringing up that correlation.

Todd

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs