Larry Wall's comments on Ruby

I think Gavin is right… we don’t “add” strings, we concatenate them.
Using the + operator to mean “concatenate” violates our eighth grade
algebra sensibilities. It’s, um, surprising.

Note that the often-awkward Perl uses . as a string concatenation
operator, not +. This is one of the things Perl got right and Ruby got
wrong, imho.

dblack@candle.superlink.net
09/10/02 09:35 AM
Please respond to ruby-talk

···

To: ruby-talk@ruby-lang.org (ruby-talk ML)
cc:
Subject: Re: Larry Wall’s comments on Ruby

Hello –

On Tue, 10 Sep 2002, nico wrote:

On September 10, 2002 04:38 am, Gavin Sinclair wrote:

I’m not convinced that it’s unnatural. We don’t know the types of a
and

b, and for some objects a and b, a + b != b + a.

I’m interested what you think the alternative is, or an argument
against

the above, and how you would like to see a + b defined in Ruby.

Gavin

I find that highly unnatural because we’ve been learning since grade
school
that a + b = b + a.

If the objects don’t satisfy that property they should be using a
different
symbol.

On the other hand, in grade school you probably weren’t adding
strings.

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hello –

I think Gavin is right… we don’t “add” strings, we concatenate them.
Using the + operator to mean “concatenate” violates our eighth grade
algebra sensibilities. It’s, um, surprising.

I have to ask… how much surprise or learning curve is really
involved in finding out that a language uses ‘+’ to concatenate
strings? I don’t mean to sound gruff – I’m just surprised (!) by
what seems to be the extreme fine-tunedness of people’s expectations.
Eighth grade seems like a long time ago… (and probably was longer
for me than for most people here :slight_smile: Was everything so rigidly set so
long ago, that the slightest expansion or reinterpretation really
causes problems?

Note that the often-awkward Perl uses . as a string concatenation
operator, not +. This is one of the things Perl got right and Ruby got
wrong, imho.

You can’t blame Ruby, though – after all, ‘.’ is already doing quite
a lot :slight_smile:

David

···

On Tue, 10 Sep 2002 David.Stagner@mpls.frb.org wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Agreed. Until now, I still mistakenly use the “.” operator from time to
time in Ruby, just because of the previous Perl experience, which was
very natural.

Regards,

Bill

···

===========================================================================
David.Stagner@mpls.frb.org wrote:

I think Gavin is right… we don’t “add” strings, we concatenate them.
Using the + operator to mean “concatenate” violates our eighth grade
algebra sensibilities. It’s, um, surprising.

Note that the often-awkward Perl uses . as a string concatenation
operator, not +. This is one of the things Perl got right and Ruby got
wrong, imho.

Anyone that has studied abstract algebra won’t be overly confused by
this, as the first entry into group theory will leap you into addition
systems that don’t work the way you used to expect.

Admittedly, that’s a long way from eighth grade algebra.

But on the other hand, if you’re going to get anywhere in being a
computer programmer, you have got to be cognizant of the fact that
addition on computers doesn’t work with the “abstract purity” it did
in grade eight:

a) 1.0 + 0.000000001 may not add up to exactly what you expected.

b) 2147352576 + 175000 often will not add up to 2147527576 unless you
are using Common Lisp, where that can revert to a BIGNUM.

Computer addition generally isn’t like grade eight.

···

The world rejoiced as David.Stagner@mpls.frb.org wrote:

This is a multipart message in MIME format.
–=alternative 0051BBBD86256C30=
Content-Type: text/plain; charset=“us-ascii”

I think Gavin is right… we don’t “add” strings, we concatenate them.
Using the + operator to mean “concatenate” violates our eighth grade
algebra sensibilities. It’s, um, surprising.

Note that the often-awkward Perl uses . as a string concatenation
operator, not +. This is one of the things Perl got right and Ruby got
wrong, imho.


(concatenate 'string “chris” "@cbbrowne.com")
http://www.ntlug.org/~cbbrowne/sap.html
But what can you do with it? – ubiquitous cry from Linux-user
partner. – Andy Pearce, ajp@hpopd.pwd.hp.com

Hi –

Agreed. Until now, I still mistakenly use the “.” operator from time to
time in Ruby, just because of the previous Perl experience, which was
very natural.

But then what would Ruby use for method calls on strings? Honestly, I
don’t think this can be cited as an example of an incorrect choice in
Ruby.

On the Perl topic: I knew I was definitely hooked on Ruby when I had
occasion to write a Perl script and (a) left out semi-colons; (b)
wrote calls to “puts”; © found myself writing things like:
@array.map:slight_smile:

David

···

On Wed, 11 Sep 2002, William Djaja Tjokroaminata wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Christopher Browne wrote:

Anyone that has studied abstract algebra won’t be overly confused by
this, as the first entry into group theory will leap you into addition
systems that don’t work the way you used to expect.

I never heard about “noncommutative sum” in algebra. I think in
every algabraic structure, the sum is commutative. E.g. in Group
Theory, the group opertion is denoted by + as long as the group is
Abelian, that is commutative but it is always denoted by * for
noncommutative groups.

I, as a mathematician, still find it very intuitive and natural to
denote the concatenation of strings by “+”. I have no problems with
it and this would be the last thing I would change in Ruby.

b) 2147352576 + 175000 often will not add up to 2147527576 unless you
are using Common Lisp, where that can revert to a BIGNUM.

… or Ruby …

Regards, Christian

And I feel the need to weigh in here, too. Not everyone is surprised by
overloading. Context pretty often resolves overloads easily, even in the
mind of humans reading code.

For instance, when you read the the above paragraph did you see red? And if
you read the next paragraph, your head will head you in the right direction
(or left, or correct). If I lead you down the wrong path, you have been
lead, unless you use lead to protect you from the radiowaves I’m using as a
mind-control device. And did you notice I used two 'the’s in the first
paragraph of this sentence? Probably one too many.

Hopefully, our code doesn’t look this bad, but my point is that we deal in
ambiguity regularly. We resolve both symbols and sounds contextually and
are quite adept at it. We do so because it is easier to re-use a symbol,
resolving ambiguities as we go, than to create and burn in a new
symbol/semantic combo.

Drew

···

-----Original Message-----
From: dblack@candle.superlink.net [mailto:dblack@candle.superlink.net]
Sent: Tuesday, September 10, 2002 11:12 AM
To: ruby-talk ML
Subject: Re: Larry Wall’s comments on Ruby

Hello –

On Tue, 10 Sep 2002 David.Stagner@mpls.frb.org wrote:

I think Gavin is right… we don’t “add” strings, we concatenate them.
Using the + operator to mean “concatenate” violates our eighth grade
algebra sensibilities. It’s, um, surprising.

I have to ask… how much surprise or learning curve is really
involved in finding out that a language uses ‘+’ to concatenate
strings? I don’t mean to sound gruff – I’m just surprised (!) by
what seems to be the extreme fine-tunedness of people’s expectations.
Eighth grade seems like a long time ago… (and probably was longer
for me than for most people here :slight_smile: Was everything so rigidly set so
long ago, that the slightest expansion or reinterpretation really
causes problems?

Note that the often-awkward Perl uses . as a string concatenation
operator, not +. This is one of the things Perl got right and Ruby got
wrong, imho.

You can’t blame Ruby, though – after all, ‘.’ is already doing quite
a lot :slight_smile:

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Agreed. Until now, I still mistakenly use the “.” operator from time to
time in Ruby, just because of the previous Perl experience, which was
very natural.

I used to bounce back and forth between writing or maintaining ActiveServer
Page code written in JavaScript and VBScript. VB uses the ampersand to
concat strings; JavaScript used ‘+’. If one mistakenly uses the ampersand
in JavaScript, it simply takes it as a logic operation and goes merrily in
its way …

James

Christopher Browne cbbrowne@acm.org writes:

Anyone that has studied abstract algebra won’t be overly confused by
this, as the first entry into group theory will leap you into addition
systems that don’t work the way you used to expect.

Really? I have been doing abstract algebra and algebraic geometry for
something like six or seven years, and I have never seen anyone use
the symbol ‘+’ to denote a non-commutative operation …

···


Tord Romstad

Ruby could use a different operator, which is what I’ve read that perl6
will do, since it is also going to be using “.” for method calls.

I think “+” is more natural to me for concatenation than “*” or “/”, and
I would expect that even a Perl programmer would agree. As for “+” vs.
"." or “_” or “~”, I feel at home with “+” because of my experience with
BASIC. The fact that it has an overloaded meaning doesn’t bother me,
since I’m used to having symbols with overloaded meaning in mathematics
(sigma, for example, can indicate standard deviation or 2-D density; it
just depends on the context).

Paul

···

On Wed, Sep 11, 2002 at 12:37:12AM +0900, dblack@candle.superlink.net wrote:

Hi –

On Wed, 11 Sep 2002, William Djaja Tjokroaminata wrote:

Agreed. Until now, I still mistakenly use the “.” operator from time to
time in Ruby, just because of the previous Perl experience, which was
very natural.

But then what would Ruby use for method calls on strings? Honestly, I
don’t think this can be cited as an example of an incorrect choice in
Ruby.

Oh yes, the consequence is there will more syntax in terms of
free-floating period (period with white space before and after), which
will be different from a period attached to its left operand, which still
can be used for method calls on strings. I am not proposing this at
all; it just felt natural in Perl.

On the other hand, this additional syntax is not completely an exception
by itself. There is already the “&” special syntax for Proc/block, which
is not strictly object-oriented.

Regards,

Bill

···

===========================================================================
dblack@candle.superlink.net wrote:

Hi –

On Wed, 11 Sep 2002, William Djaja Tjokroaminata wrote:

Agreed. Until now, I still mistakenly use the “.” operator from time to
time in Ruby, just because of the previous Perl experience, which was
very natural.

But then what would Ruby use for method calls on strings? Honestly, I
don’t think this can be cited as an example of an incorrect choice in
Ruby.

On the Perl topic: I knew I was definitely hooked on Ruby when I had
occasion to write a Perl script and (a) left out semi-colons; (b)
wrote calls to “puts”; © found myself writing things like:
@array.map:slight_smile:

If I lead you down the wrong path, you have been
lead,

Joke, troll, or mistake?

I’ve never been lead. Always flesh and blood.
I’ve been led, though.

Hal

Perl might not have used . for string concatenation were it not for the
number/string morphing nature of perl scalars.

In Ruby a variable’s type tells us what it is, in Perl the operators
provide context as to what a scalar ought to be viewed as, and this
is why they need an “extra” set of comparison operators e.g.

perl

$a = '123 ';
$b = 45;

$a + $b => 168

$a . $b => ‘123 45’

$a > $b => 1

$a gt $b => a false value

I prefer the explicitness of ruby (requiring .to_?), and its overloading
of + isn’t too surprising e.g.

2 + 2 => 4
"123 " + “45” => “123 45”
[1,2,3] + [4,5] => [1, 2, 3, 4, 5]

Mike

···

In article 20020910121025.E20993@atdesk.com, Paul Brannan wrote:

But then what would Ruby use for method calls on strings? Honestly, I
don’t think this can be cited as an example of an incorrect choice in
Ruby.

Ruby could use a different operator, which is what I’ve read that perl6
will do, since it is also going to be using “.” for method calls.

I think “+” is more natural to me for concatenation than “*” or “/”, and
I would expect that even a Perl programmer would agree. As for “+” vs.
"." or “_” or “~”, I feel at home with “+” because of my experience with
BASIC. The fact that it has an overloaded meaning doesn’t bother me,
since I’m used to having symbols with overloaded meaning in mathematics
(sigma, for example, can indicate standard deviation or 2-D density; it
just depends on the context).


mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA

The >/gt dichotomy prevented me from ever grokking Perl. That was unnatural!

Gavin

···

----- Original Message -----
From: “Mike Stok” mike@stok.co.uk

In Ruby a variable’s type tells us what it is, in Perl the operators
provide context as to what a scalar ought to be viewed as, and this
is why they need an “extra” set of comparison operators e.g.

perl

$a = '123 ';
$b = 45;

$a + $b => 168

$a . $b => ‘123 45’

$a > $b => 1

$a gt $b => a false value

I prefer the explicitness of ruby (requiring .to_?), and its overloading
of + isn’t too surprising e.g.

2 + 2 => 4
"123 " + “45” => “123 45”
[1,2,3] + [4,5] => [1, 2, 3, 4, 5]

Mike

The >/gt dichotomy prevented me from ever grokking Perl. That
was unnatural!

The mnemonic there was to use the “stringish” comparitors to compare
values as strings (since, as the poster noted, context made the
difference, not the data).

···

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Yahoo! - We Remember
9-11: A tribute to the more than 3,000 lives lost
http://dir.remember.yahoo.com/tribute

The >/gt dichotomy prevented me from ever grokking Perl. That was
unnatural!

The mnemonic there was to use the “stringish” comparitors to compare
values as strings (since, as the poster noted, context made the
difference, not the data).

Yes, I’m aware of that. But I kept getting errors in my code that were
hard to work out. Even though I “knew” the difference, errors kept
slipping in because it’s not a natural difference.

I haven’t really explained myself well, I know.

Gavin