[Tutor] Some sample code: review?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Nov 10 17:16:31 CET 2006

> Some of the names and comments are confusing, I've commented below. 
> Other than that it looks good to me.

>>      def __init__(self, default_str=str,
>>                         recursive_str=lambda obj, dstr: "..."):
> What are the arguments to default_str?

Ah, good.  I should document that default_str must be able to take any 
object and return a string.

> dstr is not a very explanatory name, maybe deep_str would be better.

Ok, I'll change this.

>>      def __deepstr(self, obj, _seen):
> I would call it 'seen', it isn't an attribute so why the _ ?

Good point.  Why the heck did I do that?  Thanks for catching that.

>>      def register(self, handler):
>>          """register: (object (object -> string) -> string or None)
> Maybe it's just me but I don't have a clue what 'object (object ->
> string)' is trying to convey.

Alan intepreted it the way I intended:

> register takes a handler argument that should be a callable object which 
> in turn takes a stringlike argument and returns either a string or None

I should, though, rephrase the signature as:

     register: object str_function -> string or None

to be more readable.  Separately, I can then define that a 'str_function' 
is a callable that takes anything and turns it into a string.

Thanks Alan and Kent!

More information about the Tutor mailing list