Design thought for callbacks

Cem Karan cfkaran2 at gmail.com
Mon Feb 23 06:47:10 EST 2015


On Feb 22, 2015, at 5:29 PM, Laura Creighton <lac at openend.se> wrote:

> In a message of Sun, 22 Feb 2015 17:09:01 -0500, Cem Karan writes:
> 
>> Documentation is a given; it MUST be there.  That said, documenting
>> something, but still making it surprising, is a bad idea.  For
>> example, several people have been strongly against using a WeakSet to
>> hold callbacks because they expect a library to hold onto callbacks.
>> If I chose not to do that, and used a WeakSet, then even if I
>> documented it, it would still end up surprising people (and from the
>> sound of it, more people would be surprised than not).
> 
>> Thanks, Cem Karan
> 
> No matter what you do, alas, will surprise the hell out of people
> because callbacks do not behave as people expect.  Among people who
> have used callbacks, what you are polling is 'what are people
> familiar with', and it seems for the people around here, now,
> WeakSets are not what they are familiar with.

And that's fine.  I know that regardless of what I do, some people are going to be surprised.  I'm trying to develop APIs that reduce that surprise as far as possible.  That means I can spend more time coding and less time answering questions... :)

> But that is not so surprising.  How many people use WeakSets for
> _anything_?  I've never used them, aside from 'ooh! cool shiny
> new language feature!  Let's kick it around the park!'  That people
> aren't familiar with WeakSets doesn't mean all that much.

Actually, I use them when building caches of stuff, and I use weak references when I have trees of stuff so the child nodes know of, but don't hold onto, their parents.  But I agree with you, there aren't a huge number of use-cases.

> The question I have is does this architecture make things harder,
> easier or about the same to debug?  To write tests for? to do Test
> Driven Design with?

Good questions!  That was why I was asking about 'gotchas' with WeakSets originally.  Honestly, the only way to know for sure would be to write two APIs for doing similar things, and then see how people react to them.  The problem is, how do you set up such a study so it is statistically valid?

Cem


More information about the Python-list mailing list