r2d2 / mao.acc.umu.se (Niklas Frykholm) writes:

> >  class Msg
> >    def initialize(@name, @type, @txt)
> >    end
> >  end
> 
> I do not like the idea. Adding magic just to save typing is only a
> good idea if the magic is beautiful. This magic is not.

I agree it isn't pretty, and that the idea is probably dead. But let
me explain my motivation.

I didn't suggest this to save typing: that's rarely a good reason to
change something. Instead, I suggested it because I feel that the
other way

     def fred(param1, param2, anotherparam)
       @param1, @param2, @anotherparam = param1, param2, anotherparam

       ...

has a couple of inherent problems.

First, it's noisy. It clutters up the source, and cuts down on
communication of _real_ semantic content.

Second, it's error prone. There are two effective duplications of
'param1' in the above, and as you may know, I don't like duplication :)

Now, Ruby already has many convenience facilities built in (things
like attr_xxx) which cut down the clutter in a class definition and
eliminate some duplication at the same time. I was just angling to add 
another. I personally didn't like the syntax, but it seemed consistent
with the handling of block parameters, and was unambiguous.

I'd still like to find a way to do this without duplicating the names.


Dave