[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Conventions in ruby and the principle of least surprise

Yukihiro Matsumoto

1/27/2009 2:47:00 AM

Hi,

In message "Re: Conventions in ruby and the principle of least surprise"
on Tue, 27 Jan 2009 11:11:55 +0900, Einar Boson <einarmagnus@tistron.se> writes:

|do..end vs. {}

|I find that rather annoying but I guess it's to be able to write things
|like
|
|save_block ["name1_long", "name2_long", "short"].find {|n| n.size <=
|5}.to_sym do
| puts "hello!"
|end

Correct.

|Anyways. More serious, in my oppinion, is the fact that Array#insert and
|String#insert are destructive without having an exclamation mark. Why is
|that? I really do not expect them to change their owner.

|seriously, wtf? Why not `insert` and `insert!` that behave as expected?

The bang (!) does not mean "destructive" nor lack of it mean non
destructive either. The bang sign means "the bang version is more
dangerous than its non bang counterpart; handle with care". Since
Ruby has a lot of "destructive" methods, if bang signs follow your
opinion, every Ruby program would be full of bangs, thus ugly.

matz.

1 Answer

Julian Leviston

1/30/2009 11:32:00 PM

0

Awesome :) perhaps these little gems of what certain things mean as a
FAQ could make their way into the web site.

Sent from my iPhone

On 27/01/2009, at 1:47 PM, Yukihiro Matsumoto <matz@ruby-lang.org>
wrote:

> Hi,
>
> In message "Re: Conventions in ruby and the principle of least
> surprise"
> on Tue, 27 Jan 2009 11:11:55 +0900, Einar Boson <einarmagnus@tistron.se
> > writes:
>
> |do..end vs. {}
>
> |I find that rather annoying but I guess it's to be able to write
> things
> |like
> |
> |save_block ["name1_long", "name2_long", "short"].find {|n| n.size <=
> |5}.to_sym do
> | puts "hello!"
> |end
>
> Correct.
>
> |Anyways. More serious, in my oppinion, is the fact that
> Array#insert and
> |String#insert are destructive without having an exclamation mark.
> Why is
> |that? I really do not expect them to change their owner.
>
> |seriously, wtf? Why not `insert` and `insert!` that behave as
> expected?
>
> The bang (!) does not mean "destructive" nor lack of it mean non
> destructive either. The bang sign means "the bang version is more
> dangerous than its non bang counterpart; handle with care". Since
> Ruby has a lot of "destructive" methods, if bang signs follow your
> opinion, every Ruby program would be full of bangs, thus ugly.
>
> matz.
>