From: Robert Klemme Date: 2007-10-12T15:40:17+09:00 Subject: Re: Why does this use a block 2007/10/11, Brian Adkins : > On Oct 11, 3:33 pm, Erik Veenstra wrote: > > > So, most of your objects are immutable? > > > > Yes. (If possible...) > > > > Q: Why? > > A:http://lambda-the-ultimate.org/node/1446 > > Have you thought of programming in Haskell? ;) :-) > I'm familiar with some of the benefits of avoiding state with respect > to functional programming languages, but to impose that strictly on > Ruby seems to be working against the grain. I do code many functions > (i.e. not associated with a meaningful instance) in a functional style > w/o side effects, but when working with objects, having methods modify > the state of objects seems to be very natural and productive in Ruby. Actually programming completely without side effects defies the core of the OO paradigm. Objects simply do not make much sense if methods cannot produce side effects. > I'm curious though because of my recent research into Haskell, SML, > etc.. Do you have an example of this style of programming (frozen > objects) in Ruby that you feel is compelling? Look at all the math in Ruby - I believe it makes very much sense the way it is done today. But any collection type would be rather inefficient when you always had to create a new object for every change - at least in the Ruby world. I believe that some functional language runtime systems are pretty smart and can optimize this to a certain extend. It's all about balance. Use side effects when appropriate, use immutables when appropriate. Kind regards robert