[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: ruby wish-list

Yukihiro Matsumoto

1/31/2008 12:23:00 AM

Hi,

In message "Re: ruby wish-list"
on Thu, 31 Jan 2008 04:34:49 +0900, Roger Pack <rogerpack2005@gmail.com> writes:

|I know this is controversial, but I wish that if you did
|string_1 + object_2 (or any object) that it would just call .to_s on
|object_2 (instead of having to write it explicitly). I hate having to
|write extra .to_s's (even if it avoids ambiguity). That's just me, but
|hey :)

It used to be behave like that. But it deferred the error detection,
so I changed.

matz.

2 Answers

Ashley Wharton

1/31/2008 3:53:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Not to be "naive" - but a posting by the Yukihiro Matsumoto? ... wow! I have
only just discovered Ruby (in the last several weeks) - I have become
addicted!!! A truly amazing mind ... a great (and fun) language.

Sincere and humble regards, naive

Ashley

On Jan 30, 2008 7:22 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

> Hi,
>
> In message "Re: ruby wish-list"
> on Thu, 31 Jan 2008 04:34:49 +0900, Roger Pack <rogerpack2005@gmail.com>
> writes:
>
> |I know this is controversial, but I wish that if you did
> |string_1 + object_2 (or any object) that it would just call .to_s on
> |object_2 (instead of having to write it explicitly). I hate having to
> |write extra .to_s's (even if it avoids ambiguity). That's just me, but
> |hey :)
>
> It used to be behave like that. But it deferred the error detection,
> so I changed.
>
> matz.
>
>

Steve

1/31/2008 7:14:00 AM

0

You honestly shouldn't rely upon the programming language to do a lot of
guessing for you anyway...what if "string_1" happens to be a number,
i.e., "1", and object_2 is actually an integer, (say 5)? Should Ruby
"guess" that you want the output to be "1 5", or should it, (again
guess), that you want to convert your first argument to an integer and
thus produce 6 as your output? Of course the, (assumption), is that if
you want addition you'd be using integers in the first place, and not
strings, but that's not always the case and if you want automatic to_s,
there's an equally strong argument for to_i to operate the other way. In
either case, you're asking the language to guess what you, the programmer
want, and that would be a lot more counter-intuitive than convenient.

Steve


> Hi,
>
> In message "Re: ruby wish-list"
> on Thu, 31 Jan 2008 04:34:49 +0900, Roger Pack
> <rogerpack2005@gmail.com> writes:
>
> |I know this is controversial, but I wish that if you did |string_1 +
> object_2 (or any object) that it would just call .to_s on |object_2
> (instead of having to write it explicitly). I hate having to |write
> extra .to_s's (even if it avoids ambiguity). That's just me, but |hey
> :)
>
> It used to be behave like that. But it deferred the error detection, so
> I changed.
>
> matz.