Hi,

In message "[ruby-talk:6957] return value of mutating methods"
    on 00/12/09, Raja S. <raja / cs.indiana.edu> writes:

|Should the return value of mutating methods (syntactically indicated with a
|suffix 'bang') be specified?  Should they return value be nil or the object
|being modified?

There are three reasons for current behavior:

  (1) effectiveness; there's no effective way to tell if modification
      is happened.  separate check would be costly on many cases.

  (2) safty; since bang methods have side-effect, they often make
      programmers surprise when he finds an object referenced from
      another variable modified.  bang methods are more dangerous than
      one might think.  I know returning nil makes chaining harder,
      but I think it's worthy.

  (3) backward compatibility; there're already too many programs
      depend on this behavior.

MAEDA Shugo suggested me at the conference letting them return boolean
values, thus making bang chaining impossible.  It was attractive for
me, since it frees me from this kind of discussion for ever. ;-)

I think I have to mention two more things:

  (a) I'm not going to put bangs to ALL destructive methods like
      Scheme.  It's consistent, but makes Ruby programs too ugly.

  (b) I don't claim ALL bang methods should return nil if no
      modification happens (yet); for example, reverse! and sort!
      might be exceptions.

Hope this helps clarify my policy.

							matz.