Function attributes: a bug?

Tj tj_scarlet at yahoo.com
Sat Mar 29 17:35:45 EST 2003


Alex Martelli <aleax at aleax.it> wrote in message news:<xXkha.30095$Jg1.648224 at news1.tin.it>...
> What I DO find surprising behavior is the complication
> you have chosen to use in this closure.  What role does argument
> 'init' play -- why isn't the penultimare statement just
>     accum.list = []
> for example?  

That was my original version, and while I was researching a way to get
closures, I was perturbing it to "flex its muscles."  After all, I
might have wanted to init it in one swoop.  I understand this may lead
to bad design, but I like to make and discard mistakes while
exploring.


> If you do need to access the list, then I see why it makes sense
> to add an "accum.list = initlist" statement right before the
> "return accum", but it still seems better to use initlist in
> the body of accum -- why take an extra indirection?  Or do your
> specs require the ability to CHANGE the list being accumulated
> too, as well?

Mainly because I'd like to generalize this to accumulating things like
integers.  The shared list problem goes away with numbers, but then
without function attributes, the numbers stop being bound to their
variable names.


> I think it depends on what axis you want to judge "better" along.
> Closures are simpler than class instances when your needs are
> quite well-limited.  But if you need your solution to do a lot of
> things there comes a time in which stretching closures' modest
> abilities becomes (IMHO) too complicated (and that is well before
> it becomes impossible).  

I try to make my designs pretty abstract, always keeping in mind that
at some point I may need to switch to something more powerful. 
Actually, with this project, I'm trying to use less power,
strengthening up when I need to.  I have a Java background, and found
that I'm pretty weak at foundations.  So no exceptions or OOP until
they need to come.

Thank you, for the benchmarking analysis.  Blew my mind, I think it's
a lot more professional than the shoot-from-hip stuff I do, and I
should definitely make tools when time comes to profile.  Unit tests
too...  Thanks to everyone for their helpful advice.

Tj




More information about the Python-list mailing list