On Thu, Mar 17, 2011 at 7:34 PM, Josh Cheek <josh.cheek / gmail.com> wrote:
> On Thu, Mar 17, 2011 at 1:00 PM, Klaus Stein <usenet / istik.de> wrote:
>
>> Josh Cheek <josh.cheek / gmail.com> wrote:
>> > > [ ! should mark methods changing the receiver ]
>> >
>> > I think it should become the convention. I consider the bang to be nearly
>> > meaningless as is.
>> >
>> It is _normal_ in OO that objects change state, contrary to functional
>> languages. In functional languages any functions with side-effects are
>> considered harmful (including print and puts).
>> In OO languages changing the state of an object is common:
>>
>>
> My point is not that OO languages are immutable, it is that bang methods are
> nearly meaningless. They are too contextual and require too many rules and
> exceptions to figure out,

Hmm, I don't find it hard to be remembered that x.gsub! actually
changes x while x.gsub doesn't.

> they also frequently return nil for no reason that
> is apparent to me.

Frankly, I cannot remember having used fact (change of the receiver)
indicated by the return value.  For my usage it would be more
convenient if I could do

File.foreach do |line|
  line.chomp!.scan /.../ do
    ...
  end
end

Who would wand to do this?

File.foreach do |line|
  line.chomp! or warn "Found a line without terminator!"
    ...
  end
end

Since terminators are used to separate lines only the last line might
be without trailing line terminator anyway.

I assume, it was originally thought that the information about a
change of an object in place was somehow useful.  I guess only Matz or
whoever designed this can shed light on this design decision.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/