improve this newbie code/nested functions in Python?

Esmail ebonak at gmail.com
Fri Mar 20 09:27:23 EDT 2009


Hi!

On Mar 20, 1:06 am, Terry Reedy <tjre... at udel.edu> wrote:
>
> What you wrote are two nested classes, not functions.  

Ooops .. yes of course .. simple mistake (it was late .. :)

> In my opinion,
> neither should be nested.  Nothing is gained and something is lost.
> Neither are used by client; indeed both use client.

I nested them because I see them as components of the client which
keeps track of the connection parameters and makes the initial
connection and then hands the info off to the two threads for
processing, and then also helps the two threads communicate with
each other.

This seemed like a good choice to me, can  you (or someone else)
elaborate why this is not a good design? The idea was to encapsulate
all the client info/code in one place.

> I would rename '_parent' (misleading) as 'client' or 'user'.

good suggestion .. I chose parent or could have chosen "outer" since
I was looking for a way for the nested classes to access the
outer class

The series of assignments in __init__ in client was to store the
connection parameters as instance variables in the outer client
class. the __keepGoing__ variable is used to help the two threads
communicate with each other and know when to shut down.

This feedback is exactly the sort of thing I was looking for, thanks,
I'm looking forward to more suggestions.

Esmail



More information about the Python-list mailing list