Ruby Impressions

Mark McEahern marklists at mceahern.com
Sat Jan 12 12:04:18 EST 2002


Adam Spitz wrote:
> class Person:
>     def __init__(self, name, age, gender):
>         self.name, self.age, self.gender = name, age, gender
>         self.doSomeStuff()
>
> A lot of my __init__ methods look like that: they take a few
> parameters, store them as attributes, and then maybe do some more
> stuff. Every single time I do this, I have to write out the parameter
> list three times - once in the method signature, once on the left side
> of the equals sign, and once on the right side of the equals sign.

IMHO, you're overly focused on what *you* have to *write* and you seem not
to notice that this perceived verbosity is eminently readable to *others*.

More readable than your Ruby alternative?  To each his own, I guess.

If I shared your sense of the problem, my approach would be to focus on code
generation.  I would strive to keep the resulting code simple and readable,
avoiding all these fancy init methods that someone else is likely to look at
and have NO clue what is being initialized--or worse, what to do if they
need to modify it to intercept the initialization and do something slightly
different and/or validate the data before storing it in the instance.

Cheers,

// mark





More information about the Python-list mailing list